Python Forum
help needed plz, how to check if a string is almost the same?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help needed plz, how to check if a string is almost the same?
#3
One way of achieving desired result (with Python >=3.6):

- normalize input as Gribouillis suggested
- check whether username in list of users
- print capitalized username with Hello or Try Again

>>> username = input('login: ').split()[0].lower()
>>> users = ['jack', 'jill']
>>> if username in users:
...     print(f'Hello {username.capitalize()}')
... else:
...     print('Try again!')
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
RE: help needed plz - by Gribouillis - Apr-25-2019, 10:09 AM
RE: help needed plz - by perfringo - Apr-25-2019, 02:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I check if the first X characters of a string are numbers? FirstBornAlbratross 6 1,787 Apr-12-2023, 10:39 AM
Last Post: jefsummers
  how to check if string contains ALL words from the list? zarize 6 7,648 Jul-22-2020, 07:04 PM
Last Post: zarize
  How to check if user entered string or integer or float?? prateek3 5 11,567 Dec-21-2019, 06:24 PM
Last Post: DreamingInsanity
  How to check if value of a list is in a string? HiImNew 2 4,091 Dec-07-2017, 10:07 PM
Last Post: Larz60+
  Ho to check if string contains substring from list Rius2 2 76,813 Sep-30-2017, 07:32 PM
Last Post: Rius2
  Check to see if a string exactly matches an element in a list DBS 1 22,666 Nov-02-2016, 10:16 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

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