Programming Tutorial 1
Summary
These are the topics we learned on Week 34
Version 3.0
Programming Tutorial 1
Reminder
a) You may use any online python compiler of your choice.
b) Do not copy your code from Word document to the
compiler, it might not run.
Version 3.0
Programming Tutorial 1
BEFORE YOU
START!!
In MsWord >
Search "Options" >
Proofing >
"AutoCorrect Options…" >
Untick everything there.
Version 3.0
Programming Tutorial 1
Tutorial 1
1. Explain the error message with your own words.
a. Question 1.1
Answer:
# Type your answer here
Eg. It is saying that…
b. Question 1.2
Answer:
# Type your answer here
…
Version 3.0
Programming Tutorial 1
2. Write a program to get the following output:
Question1
Answer:
# put your code here
…
Question2
Answer:
# put your code here
…
Version 3.0
Programming Tutorial 1
3. Write a program that will ask the user input the day.
Expected output:
(Hint 1: You can use the input(“”) function to get
user’s input)
(Hint 2: You can use the concatenate operator (+)
which is the plus sign, to concatenate(join) 2 strings
together.)
Answer:
# put your code here
…
Version 3.0
Programming Tutorial 1
4. Rules for identifiers in Python programming.
Complete the table below. Choose your answer
between : valid, invalid, bad practice. Then, write
some comments if it is invalid / bad practice to tell the
reason why.
Example Validity Comments
name = “Adam” valid -
8honour = 25 invalid Cannot start with
numbers.
eight honour = 25
Honour8 = 25
eighthonour = 25 valid
eight_honour = 25
wd = 25 Variable name
without obvious
meaning
Version 3.0
Programming Tutorial 1
5. Turn the following into camel cased
Name Camel Cased
Homeroom teacher homeroomTeacher
McDonald's
Profile picture
Prime Minister
WESLEY METHODIST
SCHOOL PENANG
Version 3.0
Programming Tutorial 1
6. Type casting
(Type casting means converting the data type)
a. Write a line of code that will print the type of the
variable var1.
…
b. You have a variable named var2. Convert it into
the type of int.
# this is how we convert a variable into int type
int(var2)
c. You have a variable named var3. Convert it into
the type of float.
…
Version 3.0
Programming Tutorial 1
7. Based on the given algorithm, write the code using
Python.
Answer:
# put your code here
…
Version 3.0
Programming Tutorial 1
8. Write a set of algorithms of the program that will ask
the user to input the width and length of a rectangle.
And then calculate and show its perimeter.
(You do not need to write the code, only the
algorithms)
Answer:
Step1: Ask the user to enter the width
Step2: …
Step3: …
Version 3.0
Programming Tutorial 1
9. We will be learning 6 data types in this course.
int str float list bool None
Each variable in programming has a data type. The
data type depends on what is being assigned.
Complete the table below
Code Data type
“Hello” str
“1957”
“7 Faith”
[‘1’, ‘2’, ‘3’]
True
3.142
33
None
Version 3.0
Programming Tutorial 1
10. Explain the code below in english sentences.
Code Explanation
num1 = 22 Assign the value 22
into the variable named
"num1".
num1 = num1 + 1
print(num2+ “?”)
name = str(var1)
total = num1 / num2
haha = None
Version 3.0
Programming Tutorial 1
11. What is the output of the following program?
Answer:
…
Version 3.0
Programming Tutorial 1
12. Write a program that will ask the user for 2
numbers. Then, show the average of those 2
numbers.
Algorithm:
Step1: …
Step2: …
Code:
# put your code here
Version 3.0
Programming Tutorial 1
13. Write a program that helps to calculate a
mathematical equation. Users will just have to key in
the value of “x” and “y” and the program will help to
calculate the value of “z”
Sample output
Algorithm:
Step1: …
Step2: …
Code:
# put your code here
Version 3.0
Programming Tutorial 1
14. Why does the following code get an error when
trying to compile and run?
Answer:
…
Version 3.0
Programming Tutorial 1
15. Given the following code snippet. Complete the
table below
Write the output of the following line.
Line Output
4
5
6
7
Version 3.0
Programming Tutorial 1
16. Write the meaning of the programming terms
below
Print
Type casting
Assign
Concatenate
Syntax
int
str
Variable
Case sensitive
Version 3.0