I'm getting an Expected an indented block here's the code, thank you for any help.
#Given the menu the user will calculate the area of square, circle, rectangle
from math import pi
def main ():
#declare and initialize variables
#float radius = length = width = base = height = 0.0
radius = length = width = base = height = 0.0
#float areaCircle = areaRectangle = areaTriangle = 0.0
areaCircle = areaRectangle = areaTriangle = 0.0
#int menuChoice = 0
menuChoice = 0
#display intro
while menuChoice != 4:
#Display menu
print("Geometry Calculator")
print("1) Calculate the Area of a Circle")
print("2) Calculate the Area of a Rectangle")
print("3) Calculate the Area of a Triangle")
print("4) Quit")
#Prompt for menuChoice
if menuChoice == 1:
while radius < 0:
#prompt for radius
radius = eval(input("What is radius of circle: "))
if radius < 0:
#display invalid
print("Invalid input. Cannot be a negative value.")
#calculate areaCircle
areaCircle = pi*r**2
#display areaCircle
print("The area of the circle is: ", areaCircle)
elif menuChoice == 2:
while length < 0:
#prompt for length
length = eval(input("What is the length of the rectangle: "))
if length < 0:
#display invalid
print("Invalid input. Cannot be a negative value.")
while width < 0:
#prompt for width
width = eval(input("What is the width of the rectangle: "))
if width < 0:
#display invalid
print("Invalid input. Cannot be a negative value.")
#calculate areaRectangle
areaRectangle = length * width
#diplay areaRectangle
print("The area of the rectangle is: ", areaRectangle)
elif menuChoice == 3:
while base < 0:
#prompt for base
base = eval(input("What is the length of the base of the triangle:"))
if base < 0:
#display invalid
print("Invalid input. Cannot be a negative value.")
while height < 0:
#prompt for height
height = eval(input("What is height of triangle"))
if height < 0:
#display invalid
print("Invalid input. Cannot be a negative value.")
#calculate areaTriangle
areaTriangle = 1/2 * base * height
#display areaTriangle
print("The area of the triangle is: ", areaTriangle)
elif menuChoice == 4:
#display exit message
else:
#display invalid
print("You must choose a number between 1-4 from the menu")
The error pops up at else. I've tried indenting one at a time, probably something small i'm overlooking third week into programming.
You need some sort of placeholder for the final elif
block. You may use the standard Python non-op, pass
:
elif menuChoice == 4:
#display exit message
pass
I'm assuming this will eventually be replaced by some other code, so the problem would have resolved itself had you continued working. If you are not planning on putting anything in this block, omit it entirely. There is no need for a conditional branch that does nothing.
It's the last line (#display exit message). Add a correctly indented pass statement, until you know what to do here. You need an actual python statement here, not a comment.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.