While loop help

thomasancilleri at gmail.com thomasancilleri at gmail.com
Tue Apr 9 09:32:18 EDT 2013


I'm new to learning python and creating a basic program to convert units of measurement which I will eventually expand upon but im trying to figure out how to loop the entire program. When I insert a while loop it only loops the first 2 lines. Can someone provide a detailed beginner friendly explanation. Here is my program.

#!/usr/bin/env python
restart = "true"
while restart == "true":
#Program starts here
    print "To start the Unit Converter please type the number next to the conversion you would like to perform"
    choice = input("\n1:Inches to Meter\n2:Millileters to Pint\n3:Acres to Square-Miles\n")

#If user enters 1:Program converts inches to meters
    if choice == 1:
        number = int(raw_input("\n\nType the amount in Inches you would like to convert to Meters.\n"))
        operation = "Inches to Meters"
        calc = round(number * .0254, 2)
        print "\n",number,"Inches =",calc,"Meters"
        restart = raw_input("If you would like to perform another conversion type: true\n"

#If user enters 2:Program converts millimeters to pints  
    elif choice == 2:
        number = int(raw_input("\n\nType the amount in Milliliters you would like to convert to Pints.\n"))
        operation = "Milliliters to Pints"
        calc = round(number * 0.0021134,2)
        print "\n",number,"Milliliters =",calc,"Pints"
        restart = raw_input("If you would like to perform another conversion type: true\n")

#If user enter 3:Program converts kilometers to miles
    elif choice == 3:
        number = int(raw_input("\n\nType the amount in Kilometers you would like to convert to Miles.\n"))
        operation = "Kilometers to Miles"
        calc = round(number * 0.62137,2)
        print "\n",number,"Kilometers =",calc,"Miles"
        restart = raw_input("If you would like to perform another conversion type: true\n")



More information about the Python-list mailing list