2110101 Introduction to programming: Python

First semester 2023  (Aug-Nov)

official syllabus

This is on-line course.  Students learn from pre-class videos, participating in real-time video teaching, practice on automated Grader system, and do weekly homework (which is a substantial project in programming).  The course offers tutorial and discussion via on-line chat (almost 24x7) with a team of teaching assistants. Weekly assessment is issued with immediate result.  One midterm exam and one final exam will be administrated on-site at the faculty of engineering.  The course is delivered by lecturers' team.  Each lecturer takes care of a group of students (around 70).

The information on this site is the part of my own teaching.  I post weekly edited version of  the lecture and some additional help on doing the complex homework (all in Thai).  There are main lecture videos already available in MCV of this course.  My videos are a condensed and emphasized on particular points in the lecture, not a substitution of the main lecture video.

Summary of Python topics

previous  lecture  2020

Lecture videos

Chapter 1: How to learn, using tools, easy programming: print()  video (how to learn)

Chapter 2: Data types, variables, input, operators, expression  (no video)

Chapter 3: Basic string and list  video 

Chapter 4: Selection, if, if-else, if-elseif, flowchart  video  

Chapter 5: Repetition: for, while, break, flowchart  video  

Chapter 6: List methods, list processing  video  

Chapter 7: Function  video  

Chapter 8: String methods, string and list processing  video  

Chapter 9: Basic dict (dictionary, hash)  video 

Chapter 10: Nested loop  video

Chapter 11: Tuple/set/dict  video  

Chapter 12: Numpy  video , Numpy tutorial video    code

Chapter 13: Class and object  video 

Homework

This semester we have quite an interesting set of problems crafted by the teaching team.  Hope students have fun working on them. These are just the description of the homework.  In MCV, you will find the "pre-formed" code in colab (and a lot of example data) that you can use to write your own code and test it.

Homework 1

Lines and more

goal
1. understand the use of expression, list and function
2. familiar with saving the work, download and submit the homework
3. see the distinction between homework and Grader
4. perform the required programming task

Problem

input is a list of coordinates:
[x0,y0,x1,y1,x2,y2 ...]

write five functions:

1. middle(points,i,j)  return coordinate (x,y) of midpoint between (xi,yi) (xj,yj)
2. frame(points,i,j) return list of four points of the coordinate of the "bounding box"
3. distance(points,i,j) return length of line between (xi,yi) and (xj,yj)
4. intersection(points,p1,p2,p3,p4) return (x,y) which is the intersection of line between p1,p2 and p3,p4

Homework 2

Smart elevator

goal
understand the use of expression, list, if, and loop

problem

A building has many lifts. Given a lift with two numbers (its configuration): first number is the present floor, the second number is the destination floor.

We want to plan a trip with least amount of "travel" of the lift.  For example, we are at 5th floor and want to go to 9th floor, there are 4 lifts.

Current state of four lifts:

lift 1   3->1
lift 2   1->8
lift 3   2->2
lift 4   12->3

which one should we take?
the above example, lift 2 will stop at 8 then go to 9, one hop.  lift 4 at 20 goes down to 3 then goes up to 5 to pick us up then goes to 9, result = 5-3 + 9-5 = 6 hops.  Conclusion, take lift 2.

input is the state of the lifts (including the number of lifts) follows by the query (from a floor to the destination floor

output  show the trip

Homework 3   Tutorial video

Lottery

goal
understand the use of list processing and function

A lottery has six-digits number 000000 to 999999.  The prizes are
1) the 1st-5th prize
2) near 1st prize
3) the front three-digit prize
4) the last two-digit prize

one ticket and win more than one prize.
given the table of the value of each prize.

write functions to compute the winning money of a lottery

input a list of sublist each is the winning number and the prized money

write these functions

prize_check
next_to_first
first_digits_check
last_digits_check
total_prize

Homework 4

Road to Paris

goal
understand the use of list, if, loop, string, dict, function

problem
For Olympic games 2024 (in Paris), the volleyball team needs to pass the selection process.  The selection will divide the teams into 3 groups, each group has 8 teams.  Every team in a group will meet all others.  The first two highest rank teams will be admitted.

The ranking system is as follows:
1)  the number of win match
2)  score
win 3-0, 3-1     3 points
win 3-2          2 points
loss 2-3         1 point
loss 1-3,0-3     0 point
no show          0 point
3)  the ratio of the win set divide by the loss set (set_ratio)
4)  the ratio of the win point divide by the loss point (point_ratio)

data (example)

match_result_str
'Germany Thailand 25-22 25-22 25-20'
'Dominican_Republic Czechia 21-25 25-21 21-25 26-24 12-15'


match_result (dictionary)
{'team_1': ['Germany', 25, 25, 25], 'team_2': ['Thailand', 22, 22, 20]}
{'team_1': ['Dominican_Republic', 21, 25, 21, 26, 12], 'team_2': ['Czechia', 25, 21, 25, 24, 15]}

team_stat
'Germany': [1, 0, 3, 3, 0, 75, 64]
'Thailand': [0, 1, 0, 0, 3, 64, 75]

match_stat
{'Germany': [1, 0, 3, 3, 0, 75, 64], 'Thailand': [0, 1, 0, 0, 3, 64, 75]}
{'China': [0, 1, 1, 2, 3, 114, 107], 'Canada': [1, 0, 2, 3, 2, 107, 114]}
{'Dominican_Republic': [0, 1, 1, 2, 3, 105, 110], 'Czechia': [1, 0, 2, 3, 2, 110, 105]}


write four functions
1)  match_to_dict(match_result_str)
2)  calculate_match_stat(match_result)
3)  update(stat, match_stat)
4)  load_matches(filename)

Homework 5

Data analysis:

the number of done problem in the Grader versus your grade

goal
understand the use of tuple, set,dict

write functions (more definition are embedded in the colab notebook)

get_sid_point(stu_rec)
get_stu_max_point(stu_recs)
get_stu_max_points(stu_recss)
get_stu_quiz_poin(stu_recss)
get_stu_completed_problem(stu_recss)
get_stu_stat(stu_recss1, stu_recss2)

 where stu_recss1 is data of students doing the exam problem
  stu_ress2  is data of students practicing grader problem

stu_rec is string of student id and score such as "MrBond,20"
stu_recs is total score of one problem in the Grader {'MrBond': 50, 'stu_CompProg': 0}
stu_recss is total score of many problems in the Grader ["MrBond,20", "stu_CompProg,0", "MrBond,5],["stu_CompProg,100", "MrBond,100"]]

After all these functions are written correctly, you can use the supplied plot function to see the correlation between the number of practice problem versus the score in the exam.

last update 8 Dec 2023