COMP 1023 Introduction to Python Programming

Lab 2 How do you study COMP 1023?

Review

Welcome to the second lab of COMP 1023. In this review section, we will familiarize ourselves with Python Programming Fundamentals.

Variable Assignments and Data Types

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:

  • Integers (int): Whole numbers without a decimal point, e.g., 5, -2.
  • Floats (float): Numbers with a decimal point, e.g., 3.14, -0.001.
  • Strings (str): Sequences of characters enclosed in single or double quotes, e.g., 'Hello', "Python".
  • Booleans (bool): Represent True or False.

Example:

age: int = 25            # int
price: float = 19.99     # float
name: str = "Alice"      # str
is_student: bool = True  # bool

Input and Output

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

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

Explicit Type Conversion

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'>
Nessie in LSK
Photo by WONG, Lap Ming on 28th Jan 2026

Introduction

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.

Lab Work


How do you study COMP 1023?

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."


Before you start...

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.


Task 1 - Calculating the (minimum) recommended time to study by Lap Ming

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:

  • Pre-study before the lesson
    • Read Lecture Slides (twice each week)
    • Try out the code on the Lecture Slides (twice each week)
  • Attend two Lectures
    • Pay attention during the lectures and take notes
    • Ask the instructor(s) follow-up questions after the lecture ends.
  • Attend one Lab
    • Focus during the lab to reinforce the concepts
    • Ask the TA about any concepts you don't fully understand
  • Study after the lesson
    • Organize the notes taken during the lesson (once each week)
    • Read 3 pieces of additional material
    • Pray to Nessie 7 times

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:

  1. Get the number of weeks
  2. Calculate the total time Lap Ming recommends
  3. Print the total time Lap Ming recommends

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.


Task 2 - Calculate the time Lap Ming needs to finish lab exercise(s) and programming assignment(s)

Then Lap Ming tells you about the process he uses (and recommends) to complete lab exercises and programming assignments:

  • Review the problem description
    • Understand the tasks that need to be implemented
    • Gain an overall understanding of the lab topic
  • Understand the skeleton code
    • Identify the provided helper functions
    • Sketch on paper to help illustrate the flow
  • Implement your ideas
    • Translate your drafted ideas into code
    • Refer to the lecture notes/review section if you forget how to use certain programming tools
  • Debug and test your work
    • Check if the code functions correctly (including edge cases!)
    • Remember to debug on your local machine (don't rely on ZINC!)

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:

  1. Get the number of labs and programming assignments
  2. Calculate the total time Lap Ming needs to take
  3. Print the total time Lap Ming needs to take

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.

Resources & Sample I/O

⚠️ Important: Before you start working on your code, please unzip the downloaded file first!

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.

Sample I/O

Submission & Deadline

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.py
  • time_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.

Changelog

  • 2026-02-22:
    • Changed phrasing of "5.25 times longer than" to "5.25 as long as (4.25 times longer than)" to be mathematically correct.
    • Updated submission desription as ZINC is now available.

Frequently Asked Questions

My code doesn't work / there is an error. Here is the code. Can you help me fix it?

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.

Maintained by
  • Feel free to reach out if you have any questions! 👋
  • YU, Jieming
  • jyucu@connect.ust.hk
  • HE, Yulong
  • yhedq@connect.ust.hk
  • Last Modified:
Page Created by
Homepage