私はユーザーが値(1,2,3)を入力できるスクリプトを作成しようとしています。答えを見つけるために使うことができます。しかし、私は、ユーザが数学関数を再起動するか、メニューに戻って別の関数を選択するかを尋ねるかどうかを尋ねたい。Python 3.0+:IF文を使用してコードの一部を再起動しようとしています
私は数週間Pythonを勉強してきただけなので、どのようにすればいいのか分かりません。ありがとう!ここで
は私のコードです:
choice = int(input("What program would you like to run? \n"))
#chooses one of the programs
recarea = 1
circarea = 2
fah = 3
if choice == 1:
print("This program calculates the area and perimeter of a rectangle:")
length = float(input("Type in the length: \n"))
width = float(input("Type in the width: \n"))
area = length * width
perimeter = (2*length)+(2*width)
print("The area of the rectangle is ","{0:.2f}".format(area),"cm and the perimeter is ","{0:.2f}".format(perimeter),"cm",'\n\n')
reuse = str(input("Would you like to restart the script ?"))
if reuse == "Yes" or reuse == "yes" or reuse == "y" or reuse == "Y":
print("Restarting Script...\n")
else:
reuse == "No" or reuse == "no" or reuse == "n" or reuse == "N"
print("Returning to the menu...\n\n")
ようこそStackOverflow! [機能](https://www.tutorialspoint.com/python/python_functions.htm)をお読みになることをお勧めします。 1つの機能があれば、その機能を呼び出して再起動することができます。 –
ループを使用する必要があります。おそらくwhileループが最適でしょう。しかし、それはあまりにも広い質問です。ループをルックアップし、前述のように、関数。 – Carcigenicate