Skip to article frontmatterSkip to article content

Exercise 5 - if / elif / else statements

5 total points

Directions

  • Due: 10/06/2025 @ 11:59 p.m.
  • Change the name of your notebook to EX5_FirstLast.ipynb, where First is your first name and Last is your last name.
  • For each of the following prompts, write or modify Python code that fulfills the requirements.

Translating a set of instructions to an if / elif / else statement

Problem statement:

A user wants a program that takes an a variable named temperature and print out the following information:

  1. "The temperature is x, " where x is the value in temperature. It must be inserted into the string using an f-string.

  2. Add a second part to the message based on the following conditions:

    • If the number is greater than 100, add “and it is Very Hot!”

    • If the number is greater than 90 and less than or equal to 100, add “and it is Hot!”

    • If the number is greater than 70 and less than or equal to 90, add “and it is Warm!”

    • If the number is greater than 32 and less than or equal to 70, add “and it is Cool!”

    • If the number is less than or equal to 32, add “and it is Freezing!”

We want to print ONLY one sentence each time the program is ran

Things to think about:

  1. How can you make your life easier? What specific flow control mechanism should you use?

  2. Less than is not the same as less than or equal to

  3. Greater than is not the same as greater than or equal to

Examples:

temperature = 80

# create your message

print(message)

output should be:

"The temperature is 80, and it is Warm!"

Examples:

temperature = 105

# create your message

print(message)

output should be:

"The temperature is 105, and it is Very Hot!"
temperature = 85

# create your message

print(message)