Hello, I am very new to Python (just started yesterday) and I've written a program for converting temperatures. I get wrong C to F numbers, and when I try to go from F to C I get 0. Here is the code:

choice =1
while choice==1:
    print "1. Celcius to Ferenheit"
    print "2. Ferenheit to celsius"
    print "3. Escape"
    ham=input("Please select an option: ")
    if ham==1:
        tc=input("Put a celcius temp in: ")
        tf=(9/5)*(tc+32)
        print tf
    if ham==2:
        TF=input("Enter a Farenheit temp: ")
        TC=(5/9)*(TF-32)
        print TC
    if ham==3:
        choice=0

As first line use this and it will work.
from __future__ import division

Or.

TF = float(raw_input("Enter a Farenheit temp: "))
TC = (5/9.0)*(TF-32) #9.0 make it float

Read this.
http://www.ferg.org/projects/python_gotchas.html#contents_item_3

Where do you want me to put from__future__import division? I put it as my very first line and got a syntax error.

Solved thanks for the help

Like this and it should work.

from __future__ import division

choice =1
while choice==1:
    print "1. Celcius to Ferenheit"
    print "2. Ferenheit to celsius"
    print "3. Escape"
    ham=input("Please select an option: ")
    if ham==1:
        tc=input("Put a celcius temp in: ")
        tf=(9/5)*(tc+32)
        print tf
    if ham==2:
        TF=input("Enter a Farenheit temp: ")
        TC=(5/9)*(TF-32)
        print TC
    if ham==3:
        choice=0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.