Python Forum
Ask again if wrong guess with While.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ask again if wrong guess with While.
#5
If you would like to check against a list of names:

#! /usr/bin/env python3.9

names = ['john', 'mary', 'bob', 'sue']

while True:
    name = input('What is the name: ').lower()
    if name not in names:
        print('That name is not in the list.')
        continue
    else:
        print('That name is in the list.')
        break
Output:
What is the name: charlie That name is not in the list. What is the name: bob That name is in the list.
EduPy likes this post
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
Ask again if wrong guess with While. - by EduPy - Oct-21-2021, 04:43 PM
RE: Ask again if wrong guess with While. - by Yoriz - Oct-21-2021, 04:49 PM
RE: Ask again if wrong guess with While. - by EduPy - Oct-21-2021, 07:10 PM
RE: Ask again if wrong guess with While. - by Yoriz - Oct-21-2021, 07:25 PM
RE: Ask again if wrong guess with While. - by menator01 - Oct-21-2021, 07:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Guess the word game help jackthechampion 3 3,040 Sep-06-2023, 06:51 AM
Last Post: Pedroski55
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,576 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  I guess it's about print tsavoSG 2 2,122 Feb-08-2021, 08:34 PM
Last Post: steve_shambles
  python gives wrong string length and wrong character thienson30 2 3,025 Oct-15-2019, 08:54 PM
Last Post: Gribouillis
  can't figure out problem with number guess Galoxys 4 3,356 Oct-29-2018, 01:45 PM
Last Post: snippsat
  Guess a number Ameen 5 13,148 Apr-03-2018, 01:20 PM
Last Post: snippsat
  Guess Random Number Why i m not able to enter input Nithya Thiyagarajan 6 8,233 Jan-07-2018, 04:26 AM
Last Post: squenson
  "Guess the Number" game CTT 14 13,388 Jul-26-2017, 11:41 AM
Last Post: sylas

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020