Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Automating Access Databases With Macros

Authors: Fish Davis

1st Edition

1797816349, 978-1797816340

More Books

Students also viewed these Databases questions

Question

10-3 How has e-commerce transformed marketing?

Answered: 1 week ago

Question

2. How will you handle the situation?

Answered: 1 week ago