Welcome to the second lab of COMP 1023. In this review section, we will familiarize ourselves with Python Programming Fundamentals.
In Python, variables are used to store data values. You can assign a value to a variable using the equals
sign =. Python supports several data types, including:
int): Whole numbers without a decimal point, e.g.,
5, -2.
float): Numbers with a decimal point, e.g., 3.14,
-0.001.
str): Sequences of characters enclosed in single or double
quotes, e.g., 'Hello', "Python".bool): Represent True or False.Example:
age: int = 25 # int
price: float = 19.99 # float
name: str = "Alice" # str
is_student: bool = True # bool
To interact with the user, you can use the input() function to receive input, and the
print() function to display output.
Example:
name = input("Enter your name: ")
print("Hello, " + name + "!") # Hello, Bob!
name2 = input("Enter your name again: ")
print("Hello, ", name2, "!", sep="") # Hello, Bob!
String formatting, aside from using the + operator, allows you to insert variables into
strings in a readable and efficient way.
Using format strings (f-strings):
age: int = 25
print(f"You are {age} years old.")
Using the str.format() method: (Note: the :.3f
is used to format the number to 3 decimal places)
total: float = 19.991
print("The total is ${:.3f}".format(total))
print(f"The total is ${total:.3f}") # Equivalent to the line above
You can convert the type of a variable using explicit type conversion.
Example:
s: str = "5" # string "5"
s_i: int = int(s) # integer 5
s_f: float = float(s) # float 5.0
print(type(s), type(s_i), type(s_f)) # <class 'str'> <class 'int'> <class 'float'>
Before we dive in, please make sure you have registered your CSD account. If not, you should register your
CSD account using the CSD Password Setting
Service.
In this lab, we will use basic Python programming elements.
Last semester, one of your UGTAs, Lap Ming, frequently received the following question:
"Can you tell me how to study COMP 1023?"
Although this question is already addressed in the FAQ
section of the COMP 1023 webpage,
many students still approached Lap Ming for advice.
Since Lap Ming has his own study methods for computer science courses,
he decided to create a simple lab to help you understand his recommendations for allocating your study time
for COMP 1023.
In this lab, you will be helping him to create programs to
1) calculate Lap Ming's (minimum) recommended study hours for students taking COMP 1023 over
x weeks; and
2) calculate Lap Ming's total hours needed to complete x labs and
y programming assignments
You wonder whether you can ensure an A+ by following this guide.
"No, these recommendations are just for reference, and may not apply to every student."
In the following tasks, you must make sure that your output format is exactly the same as our given examples, so that you will not lose points in our auto-grading system, ZINC. In particular, the number of decimal places must be exactly the same as our given examples (which is 2 decimal places). If the calculated result contains more or fewer than 2 decimal places, you should make sure to round it or append decimal places, respectively, so that the value in the output will always contain 2 decimal places. You can refer to the String Formatting review section for a hint.
Lap Ming shares his recommendations on how to allocate time to study and revise COMP 1023. He recommends doing all of the following every week:
You wonder why praying to Nessie will help you study COMP 1023...
"That is for emotional support when you feel stressed due to the huge workload in HKUST..."
Lap Ming begins to talk about how cute Nessie is, but you choose to ignore him
and instead ask how much time he recommends (at a minimum) for each activity.
| Event | Time spent (hours) |
|---|---|
| Reading Lecture Slides (once) | 0.75 |
| Try out the code on Lecture Slides (once) | 0.5 |
| Attend one Lecture | 1.5 |
| Attend one Lab | 2 |
| Organize the notes taken during the lesson (once) | 1 |
| Read 1 piece of additional materials | 0.6 |
| Pray to Nessie 1 time | 0.05 |
Complete the file time_study.py so that, depending on the number of weeks, you output the total number of hour(s) Lap Ming recommends for studying.
There are 3 parts to your task:
An example, where the number 3 is the input:
Enter number of weeks: 3
The total time Lap Ming recommended is: 31.95 hour(s)
You can assume that the input will always be a positive integer.
Then Lap Ming tells you about the process he uses (and recommends) to complete lab exercises and programming assignments:
For one lab, he spends his time on each activity as follows:
| Event | Time spent on each Lab (hours) |
|---|---|
| Review the problem description | 0.31 |
| Examine the skeleton code | 0.22 |
| Write code within the skeleton | 0.43 |
| Debug and test your work | 0.14 |
Lap Ming also mentions that completing one programming assignment takes him
approximately 5.25 as long as (4.25 times longer than) completing one lab
(it's not actually that lengthy, but he wants to simplify your calculations).
Now you can proceed to complete the time_assignment.py file.
Similar to the previous task, there are 3 parts to your task:
An example where there are 5 labs and 2 programming assignments:
Enter number of lab(s): 5
Enter number of assignment(s): 2
The total time Lap Ming needs to take is: 17.05 hour(s)
You can assume that the input will always be a non-negative integer.
Extract the contents of the ZIP archive to access the skeleton code files.
This ZIP archive contains 2 files: time_study.py and time_assignment.py.
The lab assignment is due on 28th February 2026, 23:59.
We will use the online grading system ZINC to grade your lab work.
You are required to upload only the following files to ZINC:
time_study.pytime_assignment.py
Important Notice: The ZINC team is planning a system upgrade for this semester. We will notify you once the upgraded ZINC system is ready to use. Please stay tuned for further announcements.
Important Notice: ZINC is now available! Please submit your work onto the platform.
You can submit your code to ZINC as many times as you like before the deadline. Only your LAST submission will be graded. After the due date, we will regrade your work using hidden test cases. We do this to ensure that students don't just hardcode the answers, such as printing the correct outputs without really solving the problems. The hidden test cases will be similar in difficulty to the provided test cases but will use different inputs (this might not apply to the programming assignment).
Please keep in mind that getting full marks with the provided test cases before the deadline does NOT guarantee you will get full marks with the hidden test cases after the deadline, since the inputs will be different.
Because the assignment is a major course assessment, to be fair, we should not complete the tasks for you.
We can provide hints, but we will not debug for you.