add a loop that will prompt the user for the number of math questions the user would like to be presented with: import random firstnum = random.randrange(1,11) # return an int from 1 to 10 secondnum = random.randrange(1, 11) compsum = firstnum + secondnum # adds the 2 random numbers together # print (compsum) # print for troubleshooting print("What is the sum of", firstnum, " +", secondnum, "?") # presents problem to user added = int(input("Your answer is: ")) # gets user input if added == compsum: # compares user input to real answer print("You are correct!!!") else: print ("Sorry, you are incorrect")
Starting with the following code, add a loop that will prompt the user for the number of math questions the user would like to be presented with:
import random
firstnum = random.randrange(1,11) # return an int from 1 to 10
secondnum = random.randrange(1, 11)
compsum = firstnum + secondnum # adds the 2 random numbers together
# print (compsum) # print for troubleshooting
print("What is the sum of", firstnum, " +", secondnum, "?") # presents problem to user
added = int(input("Your answer is: ")) # gets user input
if added == compsum: # compares user input to real answer
print("You are correct!!!")
else:
print ("Sorry, you are incorrect")
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images