Python Forum

Full Version: Area, Perimeter Calculator. Help Pls.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi, I am a highschool student in auckland new zealand trying to write a code for a area and perimeter calculator for a square rectangle and a circle. i dont even know how to code so im asking you guys for help

Image Hosted At MyspaceGens


i stole this code from somewhere and it gives me syntax errors everytime i run it.
maybe you guys can help me understand why

chose_range:
    while true:
        decision = str(input("Would you like to calculate Area or Perimeter?"))
        if (decision == 'area'):
            decision = area
            break
        elif (decision == 'perimeter'):
            decision = perimeter
            break
        else:
            print("please insert a proper input")
    return decision
x = chose_range()
If that's the full code, you need a 'def' at the start of the first line to define the function, and the 'true' on line 2 should be capitalized.
In addition to what @ichabod801 said, names area on line#5 and perimeter on line#8 are not defined and that will raise exceptions
Oh, and parentheses after chose_range on line 1, but before the colon.
Alrighty then, ill try out what you guys said.
You need to Google it. We're happy to help, but if you can answer the question without us in 30 seconds, you should be doing that.

Beyond that, you should be hitting up a tutorial. The code you posted is so broken that it's clearly not proper Python, and you can't rely on others to fix trivial coding issues.
Also, note that the block diagram you posted has a lot more than the code you show
Image Hosted At MyspaceGens


i got syntax error :'(
Please use code tags, screenshotting code is basically never what we want to see.

If you visit any tutorial on functions, you'd know that you need parenthesis, e.g.
def chose_range():
You really should go through a tutorial.
def my_function():
    decision = str(input("Would you like to calculate Area or Perimeter? "))
    if (decision == 'area'):
        decision = 'area'
    elif (decision == 'perimeter'):
        decision = 'perimeter'
    else:
        print("Invalid input")

x = decision

print(x)
i tryed running this but all i got was

Error:
Traceback (most recent call last): File "/home/main.py", line 10, in <module> x = decision NameError: name 'decision' is not defined
Pages: 1 2