0

need help correcting! first day,first 2 hours, first python program,(only had a little dark basic)

active="on"
def ondamenu():
    print ""
    print "enter integer 1 or 2"
    print ""
    print "opt.1 find the circumference"
    print "opt.2 find the radius"
    print "opt.3 quit calculator.py"
    print ""
    return input ("enter your choice: ")
def whatsdaradius(circval):
    pie=3.14159265358979323846264338327950288
    total=circval/pie
    print circval,"รท",pie," = ",total
def radius2pie(radval):
    pie=3.14159265358979323846264338327950288
    total=radval**2*pie    
    print radval,"^2","x",pie," = ",total
while active=="on":
    print "welcome to circle pro calculator.py"
    print ""
    ondamenu()
    option=ondamenu()
    if option==1:
        whatsdaradius(input(input("enter a circumference: "))
    if option==2:
        radius2pie(input("enter a radius (ie.half diametre): "))
    if option==3:
        active<>"on"
    if option<>1 or option<>2 or option<>3:
        ondamenu()
    print "thank you!"
    print ""

ts pretty readable, but its supposed to be a calculator for finding radius or circumference and loops with a while active is on

2
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by woooee
Featured Replies
  • 1

    [CODE] if option==3: active<>"on"[/CODE]This will print "True" if active != 'on' and print "False" otherwise. <> has been deprecated so use "!=" instead. I think you want [CODE] if option==3: active = "off"[/CODE]Also you can simplify the following code. [CODE] if option<>1 or option<>2 or option<>3: ondamenu() ## ## can … Read More

1
if option==3:
        active<>"on"

This will print "True" if active != 'on' and print "False" otherwise. <> has been deprecated so use "!=" instead. I think you want

if option==3:
        active = "off"

Also you can simplify the following code.

if option<>1 or option<>2 or option<>3:
        ondamenu()
##
## can also be written as
    if option not in (1, 2, 3):
        ondamenu()

Edited by woooee: n/a

0
if option==3:
        active<>"on"

This will print "True" if active != 'on' and print "False" otherwise. <> has been deprecated so use "!=" instead. I think you want

if option==3:
        active = "off"

Also you can simplify the following code.

if option<>1 or option<>2 or option<>3:
        ondamenu()
##
## can also be written as
    if option not in (1, 2, 3):
        ondamenu()

its option==2: thats being highlighted!???

0

The problem might be the double "input" on the previous line. You did not state that there was an error in the first post, and to get any more help you will have to post the exact error message as well.

if option==1:
        whatsdaradius(input(input("enter a circumference: "))
    if option==2:
        radius2pie(input("enter a radius (ie.half diametre): "))
0

The problem might be the double "input" on the previous line. You did not state that there was an error in the first post, and to get any more help you will have to post the exact error message as well.

if option==1:
        whatsdaradius(input(input("enter a circumference: "))
    if option==2:
        radius2pie(input("enter a radius (ie.half diametre): "))

ok i see my problem look at option 1 insidewhatsdaradius(INPUT(input())
the are two inputs, fixed it and it runs but no when i enter a value at ondamenu it starts over and i enter it again and the it works,?!???and how would i clear the screen?

0

This may or may not be the problem but should be fixed.

if option<>1 or option<>2 or option<>3:
        ondamenu()
        ## should be (otherwise option never changes)
        option = ondamenu()

Then run the following code to see why you should code it as:
if option not in (1, 2, 3):

option = 1
if option<>1 or option<>2 or option<>3:
   print "ondamenu()"
else:
   print "not if"

if option =1 then it is not equal to 2, etc. You could code it as
if option<>1 and option<>2 and option<>3 also.

0

pie=3.14159265358979323846264338327950288

I think the standard computer's floating point will only use something between
3.14159265359 and
3.1415926535897931
If you want more significant digits than that you will have to use Python's decimal module. http://docs.python.org/library/decimal.html

Edited by woooee: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.