![](/img/trans.png)
[英]Python, how to move an if statement outside of a for loop without duplicating the loop
[英]how to maek it so that if a for loop ends without triggering an if statement the loop begins again (python)
我的 for 循環在一個列表中循環,我想這樣做,如果用戶輸入一個值,它在列表中找不到,我想從用戶那里獲取另一個值以在列表中檢查
import datetime as date
x = date.datetime.now()
D = []
d = int((x.strftime("%d")))
M = (x.strftime("%B"))
for i in range(1,8):
d = d + 1D.append(d)
print (M+", "+str(d))
z = str(input("enter date for booking"))
for i in D :
if i == z:
break
while True:
x = int(input("Enter a Value : "))
if x not in list:
print("Try again")
continue
print("Whatever you want to print")
break
這可以幫助您完成您的項目。 如果變量是整數,請將其保留為 int,但您可以根據變量類型將其切換為 str 或 float。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.