Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function game () that teaches children how to add single-digit numbers. The function should take an integer n as a parameter and ask

Write a function game() that teaches children how to add single-digit numbers. The function should take an integer n as a parameter and ask the child to answer n single-digit addition questions. The numbers should be chosen randomly from the range [0, 9] (that is including both 0 and 9). The user will enter the answer when prompted. Your function should print 'Correct' for correct answers and 'Incorrect' for incorrect answers. After n questions, the function should print the number of questions answered correctly. The function should also recover gracefully from non-integer values typed by the user. In those cases, the function should re-prompt the child to enter the answer without counting the invalid value either as correct or incorrect. The following shows several sample runs of the function:

image text in transcribed

I need help with the problem. I instructed to use random.randrange() and try/except if the answer isn't a digit.

Python 3.7.0 Shell File Edit Shell Debug Options Window Help Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD6 4)] on win32 Type "copyright", "credits" or "license)" for more information. RESTART : C:/Users/eve/DesktopMw8. >>>game (3) Enter answer: six Please enter your answer using digits (0-9). Enter answer: 6 Correct. Enter answer: 8 Incorrect. Enter answer: 7 Correct. You got 2 correct answers out of 3 >>>game (2) 2 + 2- Enter answer: four Please enter your answer using digits (0-9). Enter answer four Please enter your answer using digits (0-9). Enter answer: four Please enter your answer using digits (0-9). Enter answer: 4 Correct. Enter answer: 11 Correct. You got 2 correct answers out of 2 In: 15 Col: 11

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

Microsoft SQL Server 2012 Unleashed

Authors: Ray Rankins, Paul Bertucci

1st Edition

0133408507, 9780133408508

More Books

Students also viewed these Databases questions