Python Forum
Trying to create a conditional with a username
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to create a conditional with a username
#2
Note in your line 5, you're not testing if the user entered a blank name, you're testing whether it is the same as a separate input request (which is blank). That's not what you want, and it's confusing to the user.

Create some sort of loop that you stay in until your request is satisfied.

while True:
    user_name = input('Please enter your name: ')
    if user_name == '':
        print("I'm sorry, I don't see your name.  Let's try again.")
    # Could do other validation here besides just blank name.
    else:
        break

print(f"Pleased to meet you {user_name}.  Let's get started.")
Reply


Messages In This Thread
RE: Trying to create a conditional with a username - by bowlofred - Jun-20-2020, 12:12 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  AttributeError: '_tkinter.tkapp' object has no attribute 'username' Konstantin23 4 1,882 Aug-04-2023, 12:41 PM
Last Post: Konstantin23
  Hiding username and password on sql tantony 10 3,064 Oct-21-2022, 07:58 PM
Last Post: wavic
  Pulling username from Tuple pajd 21 3,646 Oct-07-2022, 01:33 PM
Last Post: pajd
  Client OS username ImPyBoy17 5 2,760 Sep-24-2019, 10:18 AM
Last Post: buran
  creating a username and pword program using a #def statement and #dictionary zcode12 3 3,197 Oct-14-2018, 04:41 AM
Last Post: volcano63

Forum Jump:

User Panel Messages

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