0% found this document useful (0 votes)
20 views

Programming Tutorial 2 (V1)

The document discusses various Python programming concepts including escape characters, operators, conditional statements using if/else, and functions defined using def. It provides examples of escape character \n, arithmetic operators like + - * / %, relational operators like == and !=, and logical operators and and or. It also demonstrates simple if/elif/else conditional statements and function definitions.

Uploaded by

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

Programming Tutorial 2 (V1)

The document discusses various Python programming concepts including escape characters, operators, conditional statements using if/else, and functions defined using def. It provides examples of escape character \n, arithmetic operators like + - * / %, relational operators like == and !=, and logical operators and and or. It also demonstrates simple if/elif/else conditional statements and function definitions.

Uploaded by

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

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.

You might also like