SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Y Daniel Lang
Chapter:
.selections
Exercise:
Programming Excercises
Question:10 | ISBN:978013274719 | Edition: 6

Question

(Game: multiplication quiz) Listing 4.4, SubtractionQuiz.py, randomly generates a subtraction question. Revise the program to randomly generate a multiplication question with two integers less than 100.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

Program:

# Generate two random double digit-digit integers
import random

num1 = random.randint(0, 100)
num2 = random.randint(0, 100)
# Prompt the student to answer "What is num1 * num2?"
answer = eval(input("What is "+ str(num1) + " * " + str(num2) + " ? "))
# Check the answer and display the result
if num1 * num2 == answer:
    print("You are correct!")
else:
    print("Your answer is wrong.\n", num1,' * ', num2, "is" , num1 * num2,'.')

OUTPUT:

What is 30 * 94 ? 489                                                                                                           
Your answer is wrong.                                                                                                           
 30  *  94 is 2820 . 

 

 

0 0

Discussions

Post the discussion to improve the above solution.