I am trying to make a simple game for learning English grammar using Python. Basically, the user inputs the verb form and Python should return 'correct' or 'incorrect'. I am trying to do this using a function:
def simple_past():
question1 = input('I ____ to the park. Input: ').lower()
if input == 'went':
print('correct')
else:
print('incorrect')
But when I type in 'went', it always sends back 'incorrect'. My question is twofold: (1) why is it returning 'incorrect' even thought I am typing in 'went', (2) is this the best way to make this kind of activity? Cheers
CodePudding user response:
def simple_past():
question1 = input('I ____ to the park. Input: ').lower()
if question1 == 'went':
print('correct')
else:
print('incorrect')
Value from input will be stored in the question1
variable. So you should be comparing question1
and 'went'
CodePudding user response:
That is the reason we should give meaningful names to variables.
def simple_past():
input_value = input('I ____ to the park. Input: ').lower()
if input_value == 'went':
print('correct')
else:
print('incorrect')