question is - Please write a program which asks the user which editor they are using. The program should keep on asking until the user types in Visual Studio Code.If the user types in Word or Notepad, the program counters with awful. Other unacceptable editor choices receive the reply not good.
The program should be case-insensitive in its reactions. That is, the same user input in lowercase, uppercase or mixed case should trigger the same reaction
expected result-
Editor: Atom
not good
Editor: Visual Studio Code
an excellent choice!
Editor: NOTEPAD
awful
Editor: viSUal STudiO cODe
an excellent choice!
my code-
mystring = 'Visual Studio Code'
mystr2 = 'Notepad'
mystr3 = 'word'
while True:
usr_input = input('Editor:')
if mystring in usr_input or mystring.upper() in usr_input or mystring.lower() in usr_input:
print('an excellent choice!')
break
elif mystr2 in usr_input or mystr2.upper() in usr_input or mystr2.lower() in usr_input:
print('awful')
elif mystr3 in usr_input or mystr3.upper() in usr_input or mystr3.lower() in usr_input:
print('awful')
else:
print('not good')
when i type in 'viSUal STudiO cODe' or 'nOtEpAd' the program prints out 'not good' instead of 'an excellent choice!' or 'awful'
You need to convert user input and other variables to lowercase using
lower()and then compare. This works well:Another way to do this is to get a list of your favourite editors and another list for other editors. Use the lower method to convert user input to lowercase and strip method to get rid of whitespaces.
Use whichever method you prefer. Also I must point out that it may not be so nice to call some editors awful. What if someone's favourite is Sublime Text?