[Tutor] Beginner problem: name 'convertToFahrenheit' is not defined

Matti/Tritlo icetritlo at gmail.com
Sat Aug 16 18:07:03 CEST 2008


I too am a Beginner at python, and i have been playing around with it for
about a week. While playing around, i decided to make a calculator program
(A Very simple one) to calculate area and also to convert farenheit to
celcius and vice versa. So, here is the code:


def options():
    print "Options:"
    print " 'p' to print options"
    print " 's' for area of square"
    print " 't' for area of triangle"
    print " 'c' for area of square"
    print " 'ce' to convert from celsius to farenheit"
    print " 'fa' to convert from fahrenheit to celcius"
    print " 'q' to quit the program"
print "Welcome to this calculator."
user = raw_input("So, What is your name? ")
print "Oh, Welcome ", user,",I´ll be your calculator to day."
print "Please select one of these options, and lets calculate!"
print options()
def positive():
    print "Must be a positive number"

def square_area(width, height):
    return width * height

def triangle_area(width, height):
    return width * height / 2

def circle_area (radius):
    return radius * 3.141562953589793

def c_to_f(c_temp):
    return 9.0 / 5.0 * c_temp + 32

def f_to_c(f_temp):
    return (f_temp - 32.0) * 5.0 / 9.0

def choice():
        choice = "p"
        while choice != "q":
            choice = raw_input("Option: ")
            if choice == "p":
                print options()
            elif choice == "s":
                print "So, you have chosen to calculate the area of a
Square."
                w = input("Please enter Width: ")
                while w <= 0:
                    positive()
                    w = input("Please enter Width: ")
                h = input("Please enter Height: ")
                while h <= 0:
                    positive()
                    h = input("Please enter Height: ")
                print "The Square´s area is: ", square_area(w,h)
            elif choice == "t":
                print "So, you have chosen to calculate the area of a
Triangle."
                w = input("Please enter Width: ")
                while w <= 0:
                    positive()
                    w = input("Please enter Width: ")
                h = input("Please enter Height: ")
                while h <= 0:
                    positive()
                    h = input("Please enter Height: ")
                print "The Triangle´s area is: ", triangle_area(w,h)
            elif choice == "c":
                print "So, you have chosen to calculate the area of a
Circle."
                r = input("Please enter radius: ")
                while r <= 0:
                    positive ()
                    r = input("Please enter radius: ")
                print "The Circle´s area is: ", circle_area (r)
            elif choice == "ce":
                print "So, you´re wondering how Celcius relates to
Farenheit."
                c = input("Please enter Celcius degree´s: ")
                print c, "Degree´s Celcius are", c_to_f(c), "Degree´s
Farenheit."
            elif choice == "fa":
                print "So, you´re wondering how Farenheit relates to
Celcius."
                f = input("Please enter Farenheit degree´s: ")
                print f,"Degree´s Farenheit are", f_to_c(f), "Degree´s
Celcius."

            else:
                print "That option does not exsist"
                choice = raw_input("Option: ")
choice()
print "Leaving eh, Well, Goodbye!"
time.sleep(5)

There you can see the Farenheit - Celcius part, and also the simple menu
system.

Hope this Helps!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080816/ef8d68ee/attachment-0001.htm>


More information about the Tutor mailing list