83.9k views
0 votes
PLEASE HELP WITH THIS "PROJECT"

Your users are young children learning their arithmetic facts. The program will give them a choice of practicing adding or multiplying.

You will use two lists of numbers.

numA = [4, 1, 6, 10, 2, 3, 7, 9, 11, 12, 5, 8]

numB = [2, 12, 10, 11, 1, 3, 7, 9, 4, 8, 5, 6]

If the user chooses adding, you will ask them to add the first number from each list. Tell them if they are right or wrong. If they are wrong, tell them the correct answer.
Then ask them to add the second number in each list and so on.

If the user chooses multiplying, then do similar steps but with multiplying.

Whichever operation the user chooses, they will answer 12 questions.

Write your program and test it on a sibling, friend, or fellow student.

Errors : Think about the types of errors a user can make. Add at least one kind of error handling to your program.

1 Answer

5 votes

numA = [4, 1, 6, 10, 2, 3, 7, 9, 11, 12, 5, 8]

numB = [2, 12, 10, 11, 1, 3, 7, 9, 4, 8, 5, 6]

operation = input("Are you adding or multiplying? (a/m)")

i = 0

if operation == "a":

while i < len(numA):

try:

answer = int(input("{} + {} = ".format(numA[i], numB[i])))

if answer == numA[i] + numB[i]:

print("You're correct!")

else:

print("You're wrong! The correct answer is {}".format(numA[i] + numB[i]))

i+=1

except ValueError:

print("Please enter a number!")

if operation == "m":

while i < len(numB):

try:

answer = int(input("{} * {} = ".format(numA[i], numB[i])))

if answer == numA[i]*numB[i]:

print("You're correct!")

else:

print("You're wrong! The correct answer is {}".format(numA[i]*numB[i]))

i+=1

except ValueError:

print("Please enter a number!")

The type of error handling we perform is ValueError handling. Instead of getting an exception when the user enters a letter when they try to answer a math problem, we tell the user to enter a number.

I hope this helps!

User Csexton
by
5.6k points