Question
Original Question Problem:

Game: learn addition) Write a program that generates two integers under 100 and prompts the user to enter the sum of these two integers. The program then reports true if the answer is correct, false otherwise. The program is similar to Listing 4.1.

Modification needed to the prgraming code:

The following modification nees to be added: the program presents random additions until the user enters -1, or the user answers incorrectly 2 questions in a row.

*image of the code I started.

untitled-1,pyjunttied-2 py 1 import random 3 Generate 2-digit random numbers 4 numberl random.randintCe,99) 5 nunber2 random.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

PROGRAM:

import random

# for executing while loop indefinitely
flag = True
# count the number of incorrect attempts in a row
count = 0

while flag:
    # Generate 2-digit random numbers
    number1 = random.randint(0, 99)
    number2 = random.randint(0, 99)

    if count < 2:
        # prompt the user to enter an answer and convert it to integer
        answer = int(input("What is " + str(number1) + " + " + str(number2) + " ? "))
        # check if it is equal to -1 or not
        if answer != -1:
            # check if answer is correct
            if number1 + number2 == answer:
                # resetting the counter
                count = 0
                # Display result
                print(number1, "+", number2, "=", answer, "is True")
            # if answer is incorrect
            else:
                # increment counter by 1
                count = count + 1
                # Display result
                print(number1, "+", number2, "=", answer, "is False")
        # if answer = -1 is given
        else:
            flag = False
            print("Answer = -1 given, exiting the program!")

    # if counter is equal to 2
    else:
        flag = False
        print("Answered incorrectly 2 questions in a row, exiting the program!")

OUTPUT:

case1 : When -1 is given on 1st try

What is 39 + 62 ? -1
Answer = -1 given, exiting the program!

case2 : When an incorrect answer is given 2 times in a row

What is 72 + 82 ? 154
72 + 82 = 154 is True
What is 65 + 56 ? 121
65 + 56 = 121 is True
What is 18 + 36 ? 35
18 + 36 = 35 is False
What is 87 + 79 ? 62
87 + 79 = 62 is False
Answered incorrectly 2 questions in a row, exiting the program!

case3 : When -1 is given after some correct answers

What is 43 + 56 ? 99
43 + 56 = 99 is True
What is 85 + 47 ? 132
85 + 47 = 132 is True
What is 69 + 33 ? 102
69 + 33 = 102 is True
What is 96 + 21 ? 100
96 + 21 = 100 is False
What is 66 + 8 ? -1
Answer = -1 given, exiting the program!

case4 : When the user inputs incorrect answers in between

What is 92 + 15 ? 107
92 + 15 = 107 is True
What is 84 + 5 ? 89
84 + 5 = 89 is True
What is 66 + 61 ? 65
66 + 61 = 65 is False
What is 19 + 37 ? 56
19 + 37 = 56 is True
What is 50 + 17 ? 67
50 + 17 = 67 is True
What is 28 + 91 ? 119
28 + 91 = 119 is True
What is 39 + 93 ? 132
39 + 93 = 132 is True
What is 99 + 64 ? 21
99 + 64 = 21 is False
What is 18 + 8 ? 8745
18 + 8 = 8745 is False
Answered incorrectly 2 questions in a row, exiting the program!

SCREENSHOTS:

Case 1:

Case 2:

Case 3:

Case 4:

Hope this helps!

Add a comment
Know the answer?
Add Answer to:
Original Question Problem: Game: learn addition) Write a program that generates two integers under 100 and prompts the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT