基本上,我試圖讓我的程式在輸入 screen_number 后回圈回 main_screen,無限期地重復直到我按 T 終止它。同時,P 應該跟蹤我在整個會話中估算的數字數量。這是我到目前為止所擁有的,我只知道如何回圈 screen_number。只是不知道如何回圈回 main_screen 或如何制作“P”函式。
main_screen = str(input("Pick W to add a new number, P to show how many numbers, high or low, have been added, or T to terminate: "))
if(main_screen == "W"):
screen_number = int(input("Input your grade: "))
if(screen_number >= 10):
print("It's high.")
elif(user_grade < 10):
print("It's low.")
if(user_menu == "T"):
print("Terminating system.")
else:
print("Invalid.")```
uj5u.com熱心網友回復:
嘗試這個:
while True:
main_screen = input("Pick W to add a new number\nP to show how many numbers high or low have been added\nT to terminate: ")
if main_screen == "W":
user_grade = int(input("Input your grade: "))
if user_grade >= 10:
print("It's high.")
elif user_grade < 10:
print("It's low.")
elif main_screen == "T":
print("Terminating system.")
break
else:
print("Invalid.")
uj5u.com熱心網友回復:
嘗試使用條件回圈并在輸入正確的輸入時中斷:
while True:
main_screen = str(input("Pick W to add a new number, P to show how many numbers,
high or low, have been added, or T to terminate: "))
if(main_screen == "W"):
screen_number = int(input("Input your grade: "))
if(screen_number >= 10):
print("It's high.")
elif(user_grade < 10):
print("It's low.")
if(user_menu == "T"):
print("Terminating system.")
return
else:
print("Invalid.")
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/329057.html
