[Tutor] Question
Alan Gauld
alan.gauld at yahoo.co.uk
Tue Apr 11 13:21:50 EDT 2023
On 11/04/2023 12:02, Prayash Bhuyan wrote:
> Loop forever if the name is not in the list
OK, So you need to add a loop in the else part of your code:
>>> for name in names:
>>> name=input("what is your name: ")
>>> name=name.casefold()
>>> group=random.randint(1,5)
>>> counter+=1
>>> if name in names and counter<=len(names):
>>> print(name,"your group is",group)
else:
while name not in names:
name = input(...).casefold()
if name not in names:
print(...)
There is a much more efficient structure you could use that
removes the need for duplicate code but this should show
the principle.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list