Taking in user input is always a little tricky because computers are very exact, while humans usually expect a bit of flexibility.
The first thing in any case is to get the user's input with input('prompt: ')
(you can replace 'prompt: '
with whatever text you want to show the user. If you are using python 2.7, you should use raw_input()
instead to make sure you get a string no matter what the user types in.
The bigger question is comparing the user input to the selected line. A naive implementation could be as simple as:
if input('prompt: ') == myline:
print('success')
else:
print('fail')
This might be a problem for users however who like to capitalize things here and there... This we can solve by just ignoring capitalization by calling myline.lower()
and input('prompt: ').lower()
on our string objects to convert all the upper case letters back to lower case.
Next imagine your user chooses to use commas vs. spaces to separate the words. You may eventually find it easiest to just explicitly tell the user they have to input their response in a fairly specific manner rather then going down the rabbit hole of taking in inexact input.
Finally if they get the answer wrong on the first go, is your program just over then or do you want to prompt them again? For this there are many good examples on this site, but I'll share this one: Asking the user for input until they give a valid response