QuestionQuestion

For this assignment, we're going to create a python program for the problem below.
You have 2 tasks:

1. Write pseudocode which clarifies and breaks the code down step by step.
2. Write python code which runs the program.

The actual program you're writing is a math game.
The program chooses from a random set of math problems and if you're correct, you get a "Correct!" message.
If you're incorrect you get a "You got it wrong!" message.
The user can quit by inputting q.
If the user doesn't input a digit, output a syntax error, "Enter an integer.".

The problem
We would like a program that repeatedly displays simple multiplication and division problems, waits for the user's answer, and checks the answer for correctness.
Each multiplication problem will have single-digit operands.
Each division problem shall be the inverse of a multiplication problem with single-digit operands, so that the answer will also be a single digit.
The program will display a prompt character '>' to let the user know it is waiting for an answer.
The program will terminate when the user presses the 'q' key.
These are the kinds of problems it should create:
8 x 9 = ?
63 / 7 = ?
56 / 7 = ?
5 x 0 = ?

It can use the 'x' to represent multiplication and '/' to represent division.

A session may look like
$ mathq
Welcome to the math question program.
4 x 8 = ?
> 32
Correct!
54 / 6 = ?
> 8
You got it wrong! 54 / 6 = 9
7 * 7 = ?
>forty-nine
Enter an integer.
4 * 5 = ?
> q
Thank you for playing mathq. Bye.
$

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import random

# print the first message
print('Welcome to the math question program.')

# loop until user enters q
while True:
    # chose a random operator / or x
    operator = random.randint(0, 1)
    # generate random operand
    op1 = random.randint(1, 9)
    op2 = random.randint(0, 9)

    # do multiplication
    result...

By purchasing this solution you'll be able to access the following files:
my_math.py and pseduocode.txt.

50% discount

Hours
Minutes
Seconds
$42.00 $21.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats