[Python] How do I loop all the way back to the beginning?

Discussão em 'Python' iniciado por Stack, Fevereiro 20, 2025.

  1. Stack

    Stack Membro Participativo

    print("================")
    print("Area Calculator")
    print("================")

    base = 0
    height = 0
    length = 0
    width = 0
    area = 0
    pie = 3.14
    shape = 0

    print("1) Triangle\n2) Rectangle\n3) Square\n4) Circle\n5) Quit")

    shape = int(input("Please type the number of the shape you would like to know the area of here: "))

    while shape > 4 or shape < 1:
    print("Incorrect input")
    shape = int(input("Please type the number of the shape you would like to know the area of here: "))
    else:
    print("continue")

    if (shape == 1):
    base = int(input("base:"))
    height = int(input("Height:"))
    area = base * height / 2
    print(area)
    elif (shape == 2):
    length = int(input("Length:"))
    width = int(input("Width:"))
    area = length * width
    print(area)
    elif (shape == 3):
    side = int(input("Side:"))
    area = side **2
    print(area)
    elif (shape == 4):
    radius = int(input("Radius:"))
    area = pie * radius **2
    print(area)

    else:
    print("Something went wrong")


    I want the user to be able to find the area of another shape after their first.

    I know I can do something like this at the end

    if not input("play again").lower() == "y":


    but not sure how to start it, having a loop inside another loop through me off. Thanks for the help!

    Continue reading...

Compartilhe esta Página