vendredi 15 mai 2020

set up if statement for temperature conversions?

The given function is:

def Temp_Conv(Temp_in, case):

Where Temp_in is an integer, and case is a string. Case can be inputted as 'C2F' (celsius to fahrenheit) or 'F2C' (fahrenheit to celsius). I only need to convert celsius to fahrenheit, so when case=='C2F', then I will apply the conversion formula. However, if case=='F2C' then the return must be 'Wrong case value'. This is how I set up my program:

def Temp_Conv(Temp_in,case):
    if case=='C2F':
        return ((Temp_in*(9/5)) + 32)
    if case=='F2C'
        return 'Wrong case value'

Is this the correct way to do this?

Aucun commentaire:

Enregistrer un commentaire