0% found this document useful (0 votes)
6 views4 pages

1117BT1

The document outlines the objectives and structure of Tutorial 1 for COMP1117B Computer Programming I, including tutorial arrangements, programming exercises, and deadlines. It covers running Python programs using IDLE and VPL on Moodle, with specific exercises on printing patterns, calculating areas, and converting time formats. Students are encouraged to practice Python basics and submit their work on time, as late submissions are not accepted.

Uploaded by

eksecondac
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

1117BT1

The document outlines the objectives and structure of Tutorial 1 for COMP1117B Computer Programming I, including tutorial arrangements, programming exercises, and deadlines. It covers running Python programs using IDLE and VPL on Moodle, with specific exercises on printing patterns, calculating areas, and converting time formats. Students are encouraged to practice Python basics and submit their work on time, as late submissions are not accepted.

Uploaded by

eksecondac
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Tutorial 1 Worksheet

COMP1117B Computer Programming I 2024-2025

Tutorial objectives:
• To take note of the tutorial arrangement for the course.
• To understand different ways to run a Python program.
• To practice the use variables and operators in Python.
• To try to use VPL in Moodle.
• To practice Python Basics.
• Deadline: 23:59 Feb 17, 2025

1. Tutorial arrangement
- Tutorial on every Tuesday 12:30pm – 1:20pm. Completion of tutorial exercises count
towards the assessment for the tutorials.
- You are encouraged to ask questions on the forum on Moodle if you need help.
- No attendance will be counted for the tutorials.
- If you have difficulties in finishing the tutorial exercises, you should attend the tutorial to get
some ideas.
- You are required to save your program and press the “Evaluate” button of the tutorial
exercises on time.
- You can evaluate as many times as you want for each exercise before the deadline but
only the last evaluated marks would be counted.
- Late work is NOT accepted.

2. Introducing IDLE
- There are many ways to run a Python program. One easiest way is to install Python on your
machine. (Download URL: https://www.python.org/downloads/ ) Instruction for different OS
can be found in https://docs.python.org/3/using/index.html .
- In this course we will be using Python 3.8.10.
- While we will be mostly using VPL on Moodle in this course, you are encouraged to install
Python on your own machine to run your own programs.

3. Interactive mode

Exercise 1.1 Hello World


Print “Hello World” in the Python Shell in IDLE.

- In IDLE, we can run simple code in the interactive console called “Python Shell”.
- Interactive mode is very useful to test-run Python code quickly.
- To complete this exercise, type print("Hello World")in the Python Shell in IDLE, you
should see the message printed when you press ENTER.
4. Script mode

Exercise 1.2 Print a pattern


Write a program to print the following pattern in IDLE:
lololo
ololol
lololo

- While interactive mode is convenient, we should always write our program in a file
(filename ending with .py) so that we can save it and run it when needed.
- In IDLE, you can start an editor by choosing File → New File (or File → Open… to open
an existing file).
- We can then write our program in the editor and save it in a file to run in script mode.
- To complete this exercise, type the following code in the editor:

# Exercise 1.2
print("lololo")
print("ololol")
print("lololo")

- Save it in a file (filename ending with .py), then select Run → Run Module or simply press
F5 to run it.
- Check if you get the correct pattern printed.

5. VPL on Moodle

Exercise 1.1 Hello World (revisited)

- VPL on Moodle is a platform that can be used to automatically evaluate your code
and feedback immediately.
- In the Moodle page, there will be one VPL activity setup for each question in the tutorial.
- To write a program in VPL, first enter the VPL activity and start writing your code.
- To complete this exercise, enter the activity “Exercise 1.1 Hello World” on Moodle, then
click on “Edit”.

- In the editor of VPL, type in the same program as in part 3 above. Click the Save

button to save the file.


- Once the file is saved, you can click on the Run button to run it. Check the output to see
if the output is correct, modify your code if needed.

- Once you think you have well completed the task, use the Evaluate button to
evaluate it. Revise your code if it does not pass the evaluation.
- Now, try to finish Exercise 1.2 in VPL.
Sample Input Expected Output
Hello World

Exercise 1.2 Print a pattern (revisited)

Sample Input Expected Output


lololo
ololol
lololo

6. Variables and operators

Exercise 1.3 Calculate area of a triangle


Write a program to store the base and height of a triangle as 10 and 4 respectively. Calculate
the area of the triangle and print the answer on screen.

Note: Area of triangle is calculated by the formula:


base × ℎ𝑒𝑖𝑔ℎ
2

- In the worksheet, we try to add tips and hints from time to time, so it is very important to
read the worksheet!
- To complete the task, we set two variables to keep the base and height of a triangle:

# Exercise 1.3
base = 10
height = 4

- Try your best to give a meaningful name to the variables. Don’t be lazy! For example, this is
not acceptable:

# DON’T DO THIS!!!
a = 10
b = 4

- To complete the task, there are two choices:


- You can calculate the area first, then print it:

# Calculate area of triangle


area = base * height / 2
print(area)

- Or you can calculate the area and print immediately without storing it:

# Calculate area of triangle


print(base * height / 2)

- Both methods are fine. The first one is easier to read especially with the variable name.
The second one is also clear especially if we add comments to explain it.

Sample Input Expected Output


20.0
Exercise 1.4 Time conversion
Write a program to ask the user to input a number (in seconds). Convert it into the format
hour, minute, second, then print the result separated by “:”. For example, if the input is 3666,
your output should be 1 : 1 : 6 (as it is 1 hour 1 minute and 6 seconds).

Sample Input Expected Output


3666 1:1:6
8 0:0:8

- Please complete Exercises 1.1 to 1.4 on Moodle.

You might also like