Introduction to Python

Form 3 - Computer

2023-2024

Floor 4 - Computer Room

Mr. Peter

Outline

Outline

If statement review

1

And/Or Condition

2

Exercises

3

If statements

if           :

1.

2.

Command1

Tab

if Condition :

Command1

False

True

Condition is like a door that controls opening and closing.

If else statements

else:

Command2

if Condition :

1.

2.

3.

4.

Command1

Tab

Tab

False

If the door is closed

It will execute command2

If elif else statements

if Condition :

1.

2.

3.

4.

Tab

Tab

elif Condition :

else:

Command3

Tab

Command2

Command1

5.

6.

False

False

Input function

Same

Differrent

1.

2.

int(

input( "Prompt message: " )

user = 

)

user = int( input("Prompt message: ") )

Same

Differrent

1.

2.

Write a Python code snippet that checks whether a given number is positive or negative.

The program should do the following:

1.

Question

Prompt the user to enter a number.

2.

Check whether the number is positive, negative, or zero.

3.

Print an appropriate message depending on the result of the check.

If elif else statement - Ex01

Save the file as "XX_YYYY_Ex01.py"

Same

Differrent

1.

2.

Write a Python code snippet that takes in a student's score and calculates their final grade based on the following requirements.

The program should do the following:

1.

Question

Prompt the user to enter a score

2.

If the average score is greater than or equal to 80, the student gets an A.

3.

If the average score is greater than or equal to 60 but less than 80, the student gets a B.

4.

If the average score is less than 60, the student gets an C.

5.

Print an appropriate grade depending on the result of the check.

If elif else statement - Ex02

Save the file as "XX_YYYY_Ex02.py"

Same

Differrent

1.

2.

Write a Python code snippet that takes in a student's score and calculates their final grade based on the following requirements.

Question

If elif else statement - Ex02

A

B

C

Save the file as "XX_YYYY_Ex02.py"

If elif else statement - Ex03

Same

Differrent

1.

2.

Write a Python code that implements the discount calculator.

The program should do the following:

1.

Question

Prompt the user to enter a pricing number.

2.

10% discount for purchases of $100 or more

3.

20% discount for purchases of $200 or more

4.

30% discount for purchases of $300 or more

5.

Print how much does the user need to pay?

Save the file as "XX_YYYY_Ex03.py"

Same

Differrent

1.

2.

Write a Python code that implements the discount calculator.

Question

30% discount

20% discount

10% discount

No discount

If elif else statement - Ex03

Save the file as "XX_YYYY_Ex03.py"