Question
PYTHON 3 I have to add a for loop to this code that will prompt the user for the number of math questions the user
PYTHON 3
I have to add a for loop to this code that will prompt the user for the number of math questions the user would like to be presented with.
Im just starting Python3 and have a basic grasp how to print and a few basic commands, but Im not sure how to enter this for loop to get the affect it is asking for.
----------------------------------------------------------------
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")
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started