Python Forum
Area, Perimeter Calculator. Help Pls.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Area, Perimeter Calculator. Help Pls.
#1
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()
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
In addition to what @ichabod801 said, names area on line#5 and perimeter on line#8 are not defined and that will raise exceptions
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
Oh, and parentheses after chose_range on line 1, but before the colon.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#5
Alrighty then, ill try out what you guys said.
Reply
#6
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.
Reply
#7
Also, note that the block diagram you posted has a lot more than the code you show
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#8
Image Hosted At MyspaceGens


i got syntax error :'(
Reply
#9
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.
Reply
#10
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
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020