Computers are playing an increasing role in education. The use of computers in edu- cation is referred to as computer-assisted instruction (CAI). Write a program that will help an elemen- tary school student learn multiplication. Use the random module to produce two positive one-digit integers. The program should then display a question, such as How much is 6 times 7? The student then types the

answer. Next, the program checks the student’s answer. If it is correct, print the string "Very good!" on the screen and ask another multiplication question. If the answer is wrong, display "No. Please try again." and let the student try the same question again repeat- edly until the student finally gets it right. A separate function should be used to generate each new question. This method should be called once when the program begins execution and each time the user answers the question correctly. [Hint: To convert the numbers for the problem into strings for the question, use function str. For example, str( 7 ) returns "7".]

What will be an ideal response?


```
# Test a student's knowledge of multiplication.

import random

# generate a random one-digit positive number
def generateNumber():
return random.randrange( 0, 10 )

# generate a multiplication problem
def generateQuestion( a, b ):
return "How much is " + str( a ) + " times " \
+ str( b ) + "?"

wrong = 0 # is answer correct?

while 1:

if not wrong:

# generate problem with answer
number1 = generateNumber()
number2 = generateNumber()
answer = number1 * number2
question = generateQuestion( number1, number2 )
wrong = 0 # return wrong to false value

print question

response = raw_input( "= " )

if response == "q":
break

if int( response ) == answer:
wrong = 0
print "Very good!"
else:
wrong = 1
print "No. Please try again."
```
How much is 6 times 4?
= 24
Very good!
How much is 5 times 1?
= 5
Very good!
How much is 8 times 4?
= 12
No. Please try again.
How much is 8 times 4?
= 32
Very good!
How much is 9 times 3?
= q

Computer Science & Information Technology

You might also like to view...

When Word 2013 opens ________ files, it converts them to Word documents so that you can edit them

Fill in the blank(s) with correct word

Computer Science & Information Technology

A computer relies on a host to propagate throughout a network.

a. Worm b. Virus c. Program d. Sniffer

Computer Science & Information Technology

____________________ is an interface standard for connecting a computer or terminal (or DTE) to a voice-grade modem (or DCE) for use on analog public telecommunications systems.?

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

What type of HTML list will automatically place a bullet point indicator in front of each item?

a. bullet list b. ordered list c. unordered list d. definition list

Computer Science & Information Technology