0

How do I improve this Python 3 code?

Hello, this is my first time here and I'm using Python version 3 to write this code. On line 4, it only accepts input answer that is "n", if you type in other input such as: "nope", "Nope", "no", or "No" line 5 would not be printed. As of now, the input option is very limited to only one form of input. How do I improve this code so that it would accept other forms of input as listed above? Thank you. 1) ur_name = input("Hello, what is your name?") 2) print("Hello," + ur_name + ".") 3) question = input("Would you like to guess? [Y/N] ") 4) if question == ("n"): #trying to figure out how to include other answer option other than "n" such as "no", "nope" etc... 5) print("awwwww") #The "print" here should be indented.

3rd Oct 2019, 6:41 AM
Kiet Huynh
3 odpowiedzi
+ 3
Try adapting this to suit your code. Create a list of responses, then iterate through the responses for a match to create your output. Example code attached https://code.sololearn.com/cQ16FHN19uQ1/?ref=app
3rd Oct 2019, 11:15 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
python is wierd but readable. 1. you can create inline if to print awww 2. use list and "in" operator to compare the input with multiple possibilities print("aww" if input("[Y/N]").lower() in ["n","no"] else "")
3rd Oct 2019, 6:59 AM
Taste
Taste - avatar
0
thank you guys.
4th Oct 2019, 2:22 AM
Kiet Huynh