Editor

Temperature Advisor

Beginner · Write the code · from Python If-Else: Conditions, Elif, Nested Ifs, and Ternary

From the lesson: Python If-Else: Conditions, Elif, Nested Ifs, and Ternary

Every day you make hundreds of decisions. If it's raining, you grab an umbrella. If the traffic light is red, you stop. If your phone battery is below 20%, you look for a charger. These are all conditional decisions - you check something and act based on the result.

Read the lesson

Write a program that gives clothing advice based on temperature. A variable temp is given with the value 22.

Rules:

  • If temp is 30 or above, print "Wear shorts"
  • If temp is 20 or above (but below 30), print "Wear a t-shirt"
  • If temp is 10 or above (but below 20), print "Wear a jacket"
  • Below 10, print "Wear a coat"
  • Expected output:

    Wear a t-shirt
    temp = 22
    # Give clothing advice based on temperature

    More if else exercises

    All Python exercises · 50 practice problems · Control Flow quiz