Python Forum
Troubling question - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Troubling question (/thread-30923.html)



Troubling question - charlottelol - Nov-13-2020

Hello everyone,

I need to find out how to see if the users answer is correct. In this, the answers are randomly generated and the user has to input an answer and the program will check if it is correct or nott.Could someone please help, i will input my existing code.
import random
print('Random number generator')
lowest_option= int(input('What is the lowest option? '))
highest_option= int(input('What is the highest option? '))

counter = 0

for count in range(5):
    limit1 = random.randint(lowest_option, highest_option)
    limit2 = random.randint (lowest_option, highest_option)
   
    player_answer = int(input('What is the answer to' + str(limit1) + '+' + str(limit2) + ' ?'))



RE: Troubling question - Gribouillis - Nov-13-2020

Use
correct = player_answer == limit1 + limit2