[Tutor] I cant fix this bug
Gina
ginarf at comcast.net
Wed Dec 19 02:05:37 CET 2012
I have Python version 3.
when the program begins, it prints out the main menu and then asks you
for your choice - just like it is supposed to
you enter your choice, and the next menu pops up, and below the menu it
says "None" on the line before your next choice is asked for
i dont know why it does this or how to make it go away
sorry the menu looks funny(they are supposed to be shapes)
i didnt include the code for all of the functions but the same thing
happens for each of the four choices
CODE BEGINS HERE:
def parallelogram_area(side1, side2):
"find the area of a parallelogram"""
solution1 = float(side1 * side2)
return solution1
def quadrilateral_perimeter(side1, side2, side3, side4):
"""find the perimeter of a quadralateral"""
solution1 = float(side1 + side2 + side3 + side4)
return solution1
def trapezoid_area(side1, side2, height):
"""find the area of a trapazoid"""
solution1 = float(side1 + side2)
solution2 = float((height)/2)
solution3 = float(solution1 * solution2)
return solution3
def menu_quad():
"""Display menu for quadrilaterals"""
print(
"""
Quadrilaterals
0 - Return to main menu
1 - Parallelogram (area)
2 - Trapezoid (area)
3 - Quadrilateral(perimeter)
"""
)
choice = None
while choice != "0":
print(
"""
Menu
0 - Exit
1 - Quadrilaterals 3 - Circles
_________________ **
| | ********
| | ************
| | **************
| | **************
| | ************
|_________________| ********
**
2 - Triangles 4 - 3D
/\ /|\
/ \ / | \
/ \ / | \
/ \ / | /
/ \ / | /
/__________\ /_____|/
"""
)
choice = input("Choice: ")
if choice == "0":
print("Good-bye.")
#main
if choice == "1":
#quadrilaterals
print(menu_quad())
quad_choice = input("Choice: ")
if quad_choice == "0":
print()
if quad_choice == "1":
#parallelogram
side1 = float(input("Side 1: "))
side2 = float(input("Side 2: "))
area = parallelogram_area(side1, side2)
print("The area of the parallelogram is", area)
if quad_choice == "2":
#trapezoid
side1 = float(input("Side 1: "))
side2 = float(input("Side 2: "))
height = float(input("height: "))
area = trapezoid_area(side1, side2, height)
print("The area of the trapezoid is", area)
if quad_choice == "3":
#quadrilateral
side1 = float(input("Side 1: "))
side2 = float(input("Side 2: "))
side3 = float(input("Side 3: "))
side4 = float(input("Side 4: "))
perim = quadrilateral_perimeter(side1, side2, side3, side4)
print("The perimeter of the quadrilateral is", perim)
else:
print("Sorry, that is not a valid choice :(")
input("Press enter to exit.")
More information about the Tutor
mailing list