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")

EBK JAVA PROGRAMMING
8th Edition
ISBN:9781305480537
Author:FARRELL
Publisher:FARRELL
Chapter2: Using Data
Section: Chapter Questions
Problem 12PE
icon
Related questions
Question

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")

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Basics of loop
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,