Tutorial 2
Summary
Today’s topics How they look like
Escape character \n
Using of more operators +-*/ % == != and or
if if if
Conditional statement if else elif
elif
else
Functions def abc():
Before you start, disable all the auto
correct functions.
Q1: You can only use 1 print() statement to get this
output:
# Edit the code below:
print("********")
Q2: Given 7 lines of codes and these error messages:
Explain the error message
Type your answer here……………………….
Q3: Edit the code below in order to get this output:
def function1():
print("Output line 1")
print("Output line 2")
print("Output line 3")
def function2():
print("Output line 4")
print("Output line 5")
print("Output line 6")
# function call
function1()
function2()
Q4: The following codes are a bit messy. Rearrange
them into 2 functions called printColors() and
printFoods().
print("Burger")
print("Cabbage")
print("Red")
print("Cyan")
print("Pizza")
print("Red Velvet cake")
print("Blue")
print("Coquelicot")
Q5: Draw a flowchart of the following code.
# use https://app.diagrams.net/?src=about to draw your flowchart and paste it here.
Q6: Write a program based on this flowchart.
Q7: Write a program based on this flowchart.
Q8: Draw a flowchart of the following code.
# use https://app.diagrams.net/?src=about to draw your flowchart and paste it here.
Q9: Write a program that will check is a given number an even number
or an odd number.
Here are 3 sample outputs for your reference:
# Code here
print("Hello world")
Hint: All even number will have 0 remainder if divided by 2.