在询问用户是否愿意后,我试图实现重新运行循环的可能性。在说不应再次运行循环后,循环将正确停止。但是,在“ continue”命令之后,循环不会再次开始。
我已经尝试阅读一些论坛帖子,但感觉有点卡住。
[^,]+,[^,]+,[ 0-9]+
答案 0 :(得分:1)
使循环继续进行的条件是"Y"
,while (a == "Y")
,但是您将值更改为"N"
。尝试切换不变值和起始值。
a = "N"
url = input("Please enter a valid url:")
while (a == "N"):
...
此外,如果使用break
控制语句退出循环,则实际上并不需要一个值来检查。尝试这样的事情:
while True:
url = input("Please enter a valid url:")
if "https://" not in url:
print("Invalid url, please try again.")
continue
print("url entered successfully!")
print("url:", url)
print("Is the given url correct?")
a = input("Yes/No:")
if str(a) == "Y" or str(a) == "y" or str(a) == "YES" or str(a) == "Yes" or str(a) == "yes":
break
elif str(a) == "N" or str(a) == "n" or str(a) == "No" or str(a) == "NO" or str(a) == "no":
print("Please try again.")
continue
else:
print("Invalid entry. Assuming correct url is given.")
break
答案 1 :(得分:0)
您的循环不会继续,因为a不再等于'Y'。在继续语句之前添加a = "Y"
,它应该可以工作