[Tutor] Type Conversion

Jessica Brink jbrink at npsd.k12.wi.us
Wed May 9 20:37:51 CEST 2007


I am doing a simple program that takes input from the user (a temp. in degrees Celsius) and converts it to a temperature in Fahrenheit.  The following program works:
 
def conversion ():
    C = input ("Enter the temperature in degrees Celcius:\n")
    F = (9.0 / 5.0) * C + 32
    print F
 
conversion ()

However, if I try to use the raw_input function, and then convert the variable to an integer, it does not work:
 
def conversion ():
    C = raw_input ("Enter the temperature in degrees Celcius:\n")
    int (C)
    F = (9.0 / 5.0) * C + 32
    print F
 
conversion ()

Am I missing a step on converting the variable C from a string to an integer, or is it not possible to do this?  I get the error that it is not possible to concatenate a str and int.
 
Thanks!
 
Jessica Brink
Business/Computer Teacher
Northland Pines High School
Eagle River, WI
715-479-4473 ext. 0701
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070509/12dfa4ac/attachment.htm 


More information about the Tutor mailing list