# [Tutor] celcius to farenheit converter.

Rikard Bosnjakovic rikard.bosnjakovic at gmail.com
Wed Apr 18 06:49:22 CEST 2007

```On 4/18/07, python at uni-code.com <python at uni-code.com> wrote:

> I found this site and I'm practicing coding and I write this script, but
> I'm unsure why its not working.  Everything goes well until it gets to the
> part where it tries to calculate the formula.  Inputs work fine anyone
> know what I did wrong?

In the future, please add what error message you get. That saves us
some type cutting and pasting the code, and running it.

The thing that's wrong with your code is that you try to multiply an
integer with a string. raw_input() returns a string, not an integer.
What you want to do is to convert it to an int first:

temp = raw_input("Insert a temperature to convert.\n")
temp_int = int(temp)

Also, print cannot mix ints and strings using string concatenation
(+). What you want to do is to use string formats.

So, the final code would be something like this:

temp = raw_input("Insert a temperature to convert.\n")
temp_int = int(temp)

type = raw_input("Now choose a convertion: Celcius(c) or Farenheit(f)")

if type == "c":
cel = (5/9)*(temp_int-32)
print "Farhrenheit %d is equal to %d celcius.\n" % (temp_int, cel)
elif type == "f":
far = (9/5)*(temp+32)
print "Farhrenheit %d is equal to %d celcius.\n" % (temp_int, far)
else:
print "Unknown Syntax!\n";

raw_input("\nPress enter to close program")

--
- Rikard - http://bos.hack.org/cv/
```