How to create a loop if contents of a list is in a variable?
Question:
I’m asking the user for a name, and if that name contains a number I want to print that they need to remove the numbers. But I can’t exit the loop afterwards.
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;
The first time I use:
for f in numbers:
if f in vad2:
It works (the code skips the loop if I don’t include any numbers) but when I do the same thing in the loop it wont work for some reason.
Answers:
Break will jump over your ‘for loop’, not over your ‘while loop’.
Modify your code like
if not vad2.isalpha(): # if you want only alphabet from your input
print()
I’m asking the user for a name, and if that name contains a number I want to print that they need to remove the numbers. But I can’t exit the loop afterwards.
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;
The first time I use:
for f in numbers:
if f in vad2:
It works (the code skips the loop if I don’t include any numbers) but when I do the same thing in the loop it wont work for some reason.
Break will jump over your ‘for loop’, not over your ‘while loop’.
Modify your code like
if not vad2.isalpha(): # if you want only alphabet from your input
print()