如何让我的代码再次请求用户输入python
我正在创建一个python程序,它为您输入的任何形状提供区域,我想知道如何使程序返回到询问用户想要什么形状如何让我的代码再次请求用户输入python,python,Python,我正在创建一个python程序,它为您输入的任何形状提供区域,我想知道如何使程序返回到询问用户想要什么形状 import math user_choice = input("Choose a shape") if user_choice == "rectangle" or "square": a = input("enter your length in centimeters here") b = input("enter your width in centimeters
import math
user_choice = input("Choose a shape")
if user_choice == "rectangle" or "square":
a = input("enter your length in centimeters here")
b = input("enter your width in centimeters here")
area = int(a) * int (b)
print(area, "cm²")
else
print"Sorry, you may have made a spelling error, or have chose a shape that we cannot calculate. Please try again"
#Code that returns to first question here?
另外,如果可能的话,由于代码很长,因为它只是重复if语句作为新形状的elif语句,所以有没有办法缩短它,这样就不会有太多的elif语句
谢谢提示:
while
循环。
import math
done = 'n'
while done == 'n':
user_choice = input("Choose a shape")
if user_choice == "rectangle" or "square":
a = input("enter your length in centimeters here")
b = input("enter your width in centimeters here")
area = int(a) * int (b)
print(area, "cm²")
else
print("Sorry, you may have made a spelling error, or have chose a shape that we cannot calculate. Please try again")
done = input("Done? (Y/N)").lower()