我試圖讓下面的代碼重復出現,直到輸入一個正確的字串值。
while True:
if value in ['man united'/span>, '曼城'/span>, '利物浦'/span>, '切爾西'/span>]。
print(tabulate(data[value])
break: break
if value not in ['man united'/span>, '曼城'/span>, '利物浦'/span>, '切爾西'/span>]。
print("You entered a wrong option, Please enter a correct option")
print(f "1: {options}")
我已經嘗試了幾種不同的方法,但無法準確實作我所尋找的目標。 這段代碼是在一個python函式中。
如果有任何幫助,我們將不勝感激。 初學Python
uj5u.com熱心網友回復:
以下是我認為你可以做的,l只是一個包含選項的串列,但你不一定要使用它。
l = ['man united'/span>, 'Man City', 'Liverpool', 'chelsea']
value = input()
while value not in l:
print("You entered a wrong option, Please enter a correct option")
print(f "1: {options}")
value = input() #or however you want to change the value variable。
print(tabulate(data[value]) #this will execute only once the correct choice has been selcted
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/309963.html
標籤:
上一篇:Java--設計模式之單例模式+保證執行緒安全的5種寫法(懶、漢、內、雙、枚)
下一篇:C 程式過早結束
