Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

this is python coding question, please includes the comments for the code Problem 2: Looping Math Game When creating games, there is often a game

this is python coding question, please includes the comments for the code image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Problem 2: Looping Math Game When creating games, there is often a "game loop": ie, until some condition is reached, the actions of the game occur. For this assignment, you will program your own pameloop by ccm Looping Math Game. This game asks the user randomly-generated math questions until the player gets five correct answers. After the game is completed, the user can repeat the game again upon request. After greeting the user, the game loop begins. It starts with telling the user the amount of questions they need to answer. After that, the game loop should follow these general steps: Generate two random integers (each ranging from 1 to 10) to serve as operands, and generate a third integer to determine the operator (either , or "). This is the math question the should ask. Display the math question to the user and let them answer it. Let the user know if they answered correctly or not. . Keep track of the correct answers. Continue to generate questions until they reach five correct answers, Once the user answers five question, tell the user they won. Then, ask the user if they would like to play again. If the user answers Y or y, let the game start over. If the user answers Norn, let the game end. Accept only those two sets of answers - ask the user again if they provide invalid input Here are a few example runs of the game. Note that the questions are randomly generated, so expect different results: Run #1 Welcome to the Looping Math Camel Answer these questions, and get 5 correct to win 3 . 10 - 30 Correct! 10 - 4 10 - 4 -6 Correcti 3.6 -18 Correct! 10 7 - 17 You win! Would you like to play again? (Y/N) T Let's play again! Answer these questions, and get 5 correct to win. 10 - 2 - 20 Correcti 3 + 10 - 13 Correct! 8 - 2 - 6 Correcti 4 - 4 - 16 Correct! Correcti You win! Would you like to play again? (Y/N) N Thank for playing Run #2 Welcome to the Looping Math Game! Answer these questions, and get 5 correct to win. 10 - 10 = 0 Correct! 2 - 7 - 5 Incorrect... Correct! 7 B -2 Incorrect... 8 - 8 - 0 Correct! 7 - 10 - 3 Incorrect... 5 + 5 = 10 Correct! 5 + 3 = 15 Correct! You win! Would you like to play again? (Y/N): maybe Invalid input. Try again! Would you like to play again? (Y/N): D Thanks for playing! Run 3 Welcome to the Looping Math Gamel Answer these questions, and get 5 Correct to win 34 - 12 Correcti 3 - - -5 Correti Correctl 155 Correct! You win! Would you like to play again? (Y/N): Y Let's play again! Answer these questions, and get correct 6 .3 - 18 10 - 7 - 70 Correct! 9 + 10 - 19 Correct! 8 - 9 - -1 Correct 10 - 3 - 7 You want Would you like to play again? (Y/N): Thanks for playing! Here are some hints to get you started: To generate the operator, generate an int, then set the operator based on the result - If you want to cleanly display the math question in the input() function, use string concatenation. To do this with two ints, you will need to convert the ints to strings the struction can do that for you. . Creating a game loop that can repeat involves more than writing just one loop. You will need to nest loops in order to do this - an outer loop to control looping the entire game, one inner loop that is the actual game loop, and another inner loop for asking the user if they would like to repeat the game

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

Database Systems For Advanced Applications 27th International Conference Dasfaa 2022 Virtual Event April 11 14 2022 Proceedings Part 2 Lncs 13246

Authors: Arnab Bhattacharya ,Janice Lee Mong Li ,Divyakant Agrawal ,P. Krishna Reddy ,Mukesh Mohania ,Anirban Mondal ,Vikram Goyal ,Rage Uday Kiran

1st Edition

3031001257, 978-3031001253

More Books

Students also viewed these Databases questions