[Tutor] decision loops

Daniel M dcmoody2 at gmail.com
Sun Feb 1 02:54:48 CET 2015


Hello. I'm a complete beginner and I’m trying to write a very basic script
to convert temperatures, just for some practice. I have that part down, but
I can’t figure out how to make the script switch between the two. What I
would like it to do is let the user go back to the “What do you wish to
convert?” part when a character is entered instead of a number for
“temperature?”. I tried using

elif m == *char*

    print (*"What do you wish to convert to?"*)

    temp = raw_input(*">> "*)



but it seems useless regardless of where I put it. It gives me the error “
return eval(raw_input(prompt))

  File "<string>", line 1, in <module>

NameError: name 't' is not defined” when I enter a character. I’m sure I’m
missing something very obvious but I can’t seem to figure it out. Where am
I going wrong?







def *ftoc*(x): #Fahrenheit to Celsius

    x == float

    y = x-32.0

    z = y * 5.0

    return z //9.0



def *ctof*(x):  #Celsius to Fahrenheit

    x == float

    y = x * 9.0

    z = y // 5.0

    return z + 32.0



print (*"What do you wish to convert to?"*)

temp = raw_input(*">> "*)



while  temp == *"c"* or temp == *"f"* and not temp == *"q"*:

    if temp == *"c"*:

        m = float(input(*"temperature?"*))

        print ftoc(m)

        print *"Celcius"*

    elif temp == *"f"*:

        m = float(input(*"temperature?"*))

        print ctof(m)

        print (*"Farenheit"*)

    elif temp == *"q"*:

        break


More information about the Tutor mailing list