Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #43169

Re: While loop help

Newsgroups comp.lang.python
Date 2013-04-09 06:57 -0700
References <b93147e7-9d17-4232-99a3-767b88f9e9ba@googlegroups.com>
Message-ID <cbd51f16-98d4-490e-92cf-7bbec3636401@googlegroups.com> (permalink)
Subject Re: While loop help
From thomasancilleri@gmail.com

Show all headers | View raw


On Tuesday, April 9, 2013 9:32:18 AM UTC-4, thomasa...@gmail.com wrote:
> 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. Also suddenly I'm getting an invalid syntax error next to my elif statements when I wasn't a minute ago. What is wrong here?
> 
> 
> 
> #!/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")

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

While loop help thomasancilleri@gmail.com - 2013-04-09 06:32 -0700
  Re: While loop help thomasancilleri@gmail.com - 2013-04-09 06:57 -0700
    Re: While loop help Dave Angel <davea@davea.name> - 2013-04-09 13:12 -0400
      Re: While loop help thomasancilleri@gmail.com - 2013-04-09 10:18 -0700
        Re: While loop help Chris Angelico <rosuav@gmail.com> - 2013-04-10 03:23 +1000
        Re: While loop help Dave Angel <davea@davea.name> - 2013-04-09 13:30 -0400
  Re: While loop help thomasancilleri@gmail.com - 2013-04-09 06:58 -0700
    Re: While loop help Chris Angelico <rosuav@gmail.com> - 2013-04-10 00:05 +1000
      Re: While loop help thomasancilleri@gmail.com - 2013-04-09 08:47 -0700
        Re: While loop help Joel Goldstick <joel.goldstick@gmail.com> - 2013-04-09 12:02 -0400
        Re: While loop help Chris Angelico <rosuav@gmail.com> - 2013-04-10 02:10 +1000
          Re: While loop help thomasancilleri@gmail.com - 2013-04-09 09:24 -0700
            Re: While loop help Joel Goldstick <joel.goldstick@gmail.com> - 2013-04-09 12:36 -0400
            Re: While loop help Chris Angelico <rosuav@gmail.com> - 2013-04-10 02:47 +1000
              Re: While loop help thomasancilleri@gmail.com - 2013-04-09 09:57 -0700
                Re: While loop help Chris Angelico <rosuav@gmail.com> - 2013-04-10 03:08 +1000
                Re: While loop help Dave Angel <davea@davea.name> - 2013-04-09 13:27 -0400
              Re: While loop help thomasancilleri@gmail.com - 2013-04-09 09:57 -0700
          Re: While loop help thomasancilleri@gmail.com - 2013-04-09 09:24 -0700
          Re: While loop help Walter Hurry <walterhurry@lavabit.com> - 2013-04-09 19:35 +0000
            Re: While loop help Dave Angel <davea@davea.name> - 2013-04-09 16:12 -0400
              Re: While loop help Walter Hurry <walterhurry@lavabit.com> - 2013-04-09 20:59 +0000
                Re: While loop help Chris Angelico <rosuav@gmail.com> - 2013-04-10 08:36 +1000
        Re: While loop help rusi <rustompmody@gmail.com> - 2013-04-10 08:59 -0700
      Re: While loop help thomasancilleri@gmail.com - 2013-04-09 08:47 -0700
  Re: While loop help Chris Angelico <rosuav@gmail.com> - 2013-04-10 00:00 +1000
  Re: While loop help thomasancilleri@gmail.com - 2013-04-09 09:49 -0700
    Re: While loop help Larry Hudson <orgnut@yahoo.com> - 2013-04-09 23:44 -0700
      Re: While loop help Larry Hudson <orgnut@yahoo.com> - 2013-04-10 20:00 -0700
  Re: While loop help jmfauth <wxjmfauth@gmail.com> - 2013-04-09 12:19 -0700

csiph-web