我要求用户提供一个名称,如果这个名称包含一个我想打印的数字,他们需要删除这些数字。但之后我不能退出循环。
numbers=['1','2','3','4','5','6','7','8','9','0']
vad2=input("To what site are you going to use the password? ")
for f in numbers:
if f in vad2:
while True:
print("You can't include numbers in the name of the site.")
vad2=input("To what site are you going to use the password? ")
numbers=['1','2','3','4','5','6','7','8','9','0']
for f in numbers:
if f in vad2
print()
else:
break;我第一次使用:
for f in numbers:
if f in vad2:它可以工作(如果我不包括任何数字,代码会跳过循环),但是当我在循环中做同样的事情时,由于某种原因它就不能工作了。
发布于 2022-10-19 19:30:45
中断会跳过你的“for循环”,而不是跳过“while循环”。修改代码,如
if not vad2.isalpha(): # if you want only alphabet from your input
print()https://stackoverflow.com/questions/74130814
复制相似问题