Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how could i include all the keys in the username? even if they're multipul? for example, if the username is "ad" and it's not include at the library

user_guess = input("Guess a letter: ")

if len(user_guess) > 1 and user_guess in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ':
    print("E1")
elif user_guess not in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ':
    print("E2")
elif(len(user_guess) > 1) and (user_guess not in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'):
    print("E3")
else:
    print(user_guess.lower())

>Solution :

if user_guess in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'

This is only true if user_guess is not a substring of the entire alphabet (in that order). I think this isn’t what you want. My guess is that you want to make sure that user_guess is only made up of alphabetic characters.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can do this yourself, by checking each character of user_guess.

Or you can just do

if user_guess.isalpha()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading