Python Forum
Area, Perimeter Calculator. Help Pls. - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Area, Perimeter Calculator. Help Pls. (/thread-14053.html)

Pages: 1 2


Area, Perimeter Calculator. Help Pls. - NZedMarine - Nov-12-2018

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()



RE: Area, Perimeter Calculator. Help Pls. - ichabod801 - Nov-13-2018

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.


RE: Area, Perimeter Calculator. Help Pls. - buran - Nov-13-2018

In addition to what @ichabod801 said, names area on line#5 and perimeter on line#8 are not defined and that will raise exceptions


RE: Area, Perimeter Calculator. Help Pls. - ichabod801 - Nov-13-2018

Oh, and parentheses after chose_range on line 1, but before the colon.


RE: Area, Perimeter Calculator. Help Pls. - NZedMarine - Nov-13-2018

Alrighty then, ill try out what you guys said.


RE: Area, Perimeter Calculator. Help Pls. - micseydel - Nov-13-2018

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.


RE: Area, Perimeter Calculator. Help Pls. - buran - Nov-13-2018

Also, note that the block diagram you posted has a lot more than the code you show


RE: Area, Perimeter Calculator. Help Pls. - NZedMarine - Nov-13-2018

Image Hosted At MyspaceGens


i got syntax error :'(


RE: Area, Perimeter Calculator. Help Pls. - micseydel - Nov-13-2018

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.


RE: Area, Perimeter Calculator. Help Pls. - NZedMarine - Nov-13-2018

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