mardi 9 mars 2021

What does line 4 syntax read in english?

Working on a set of problems and I have come across syntax that I haven't seen before. can someone explain line 4 to me what it reads in English? Is this the standard syntax to communicate range? Why isn't 15 first?

Here is the problem.

  1. Define a function that takes a temperature as a parameter.

  2. returns "Hot" if the temperature is greater than 25

  3. Returns "warm" if the temperature is between 15 and 25 including 15 and 25

  4. Returns "cold" if the temperature is less than 15

def temperature(temp):
    if temp > 25:
        return 'Hot'
    elif 25 >= temp >= 15:
        return 'Warm'
    else: 
        return 'Cold' 

Aucun commentaire:

Enregistrer un commentaire