954,525 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

python newb help (functions and while loop)

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

monstercameron
Light Poster
35 posts since Dec 2009
Reputation Points: 10
Solved Threads: 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()
woooee
Nearly a Posting Maven
2,454 posts since Dec 2006
Reputation Points: 777
Solved Threads: 714
 
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!???

monstercameron
Light Poster
35 posts since Dec 2009
Reputation Points: 10
Solved Threads: 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): "))
woooee
Nearly a Posting Maven
2,454 posts since Dec 2006
Reputation Points: 777
Solved Threads: 714
 

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?

monstercameron
Light Poster
35 posts since Dec 2009
Reputation Points: 10
Solved Threads: 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.

woooee
Nearly a Posting Maven
2,454 posts since Dec 2006
Reputation Points: 777
Solved Threads: 714
 
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

woooee
Nearly a Posting Maven
2,454 posts since Dec 2006
Reputation Points: 777
Solved Threads: 714
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: