[Tutor] Question

Prayash Bhuyan bhuyanprayash18 at gmail.com
Tue Apr 11 13:58:34 EDT 2023


Thanks

On Tue, 11 Apr, 2023, 10:52 pm Alan Gauld via Tutor, <tutor at python.org>
wrote:

> 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
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list