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.

A weather station collects data on temperature, humidity, wind speed, and precipitation. The station needs to issue warnings based on the following criteria: a "high temperature" warning if the temperature is above 35°C and the humidity is above 70%, or a "strong wind" warning if the wind speed is above 60 km/h and there is precipitation.

The program should do the following:

1.

Question

Ask the user to input the temperature in Celsius, humidity as a percentage, wind speed in km/h, and if it's raining (Yes or No).

If elif else statement - Ex01

Save the file as "XX_YYYY_Ex01.py"

2. 

Show "It's very hot and humid!" if the temperature is over 35°C and the humidity is over 70%, "It's very windy and rainy!" if the wind speed is over 60 km/h and it's raining, or "No warnings needed." if none of these conditions are met.

3. 

Make sure the user enters the right type of data: numbers for temperature, humidity, and wind speed, and Yes or No for raining.

4. 

Add notes in the code to explain what it does and what each variable means.

Same

Differrent

1.

2.

A weather station collects data on temperature, humidity, wind speed, and precipitation. The station needs to issue warnings based on the following criteria: a "high temperature" warning if the temperature is above 35°C and the humidity is above 70%, or a "strong wind" warning if the wind speed is above 60 km/h and there is precipitation.

The program should do the following:

1.

Question

Ask the user to input the temperature in Celsius, humidity as a percentage, wind speed in km/h, and if it's raining (Yes or No).

If elif else statement - Ex01

Save the file as "XX_YYYY_Ex01.py"

2. 

Show "It's very hot and humid!" if the temperature is over 35°C and the humidity is over 70%, "It's very windy and rainy!" if the wind speed is over 60 km/h and it's raining, or "No warnings needed." if none of these conditions are met.

3. 

Make sure the user enters the right type of data: numbers for temperature, humidity, and wind speed, and Yes or No for raining.

4. 

Add notes in the code to explain what it does and what each variable means.

Same

Differrent

1.

2.

A secondary school is organizing a science fair and needs to determine which students can participate. A student is allowed to participate if they meet the following requirements:

1.

Question

The student is in either Form 5 or Form 6.

If elif else statement - Ex02

Save the file as "XX_YYYY_Ex02.py"

2. 

The student has a science grade average of 85 or higher.

3. 

The student has either participated in at least 2 science extracurricular activities or has won a science award in the past year.

Write a Python program that checks if a student is eligible to participate in the science fair based on these criteria. The input from user should take in the following information:

1.

The student's level (an integer)

2. 

The student's science grade average (an integer)

3. 

The number of science extracurricular activities the student has participated in (an integer)

4. 

Whether the student has won a science award in the past year (a boolean)

Same

Differrent

1.

2.

A secondary school is organizing a science fair and needs to determine which students can participate. A student is allowed to participate if they meet the following requirements:

1.

Question

The student is in either Form 5 or Form 6.

If elif else statement - Ex02

Save the file as "XX_YYYY_Ex02.py"

2. 

The student has a science grade average of 85 or higher.

3. 

The student has either participated in at least 2 science extracurricular activities or has won a science award in the past year.

Write a Python program that checks if a student is eligible to participate in the science fair based on these criteria. The input from user should take in the following information:

1.

The student's level (an integer)

2. 

The student's science grade average (an integer)

3. 

The number of science extracurricular activities the student has participated in (an integer)

4. 

Whether the student has won a science award in the past year (a boolean)

Python - if and or statement 03

By Mr Peter

Python - if and or statement 03

  • 183