[Tutor] Type Conversion

Mike Hansen Mike.Hansen at atmel.com
Wed May 9 20:41:59 CEST 2007


 

> -----Original Message-----
> From: tutor-bounces+mike.hansen=atmel.com at python.org 
> [mailto:tutor-bounces+mike.hansen=atmel.com at python.org] On 
> Behalf Of Jessica Brink
> Sent: Wednesday, May 09, 2007 12:38 PM
> To: Teresa Stanton; Python Tutor
> Subject: [Tutor] Type Conversion
> 
> 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

Instead of int(C), I think you need C = int(C)

Mike


More information about the Tutor mailing list