Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Finally, create a main() function for your program. The purpose of this function is to control the game-logic for a Power Quiz game. The steps

Finally, create a main() function for your program. The purpose of this function is to control the game-logic for a Power Quiz game. The steps of this game are as follows:

Generate a random integer n in the range [0,4096]

Ask the user to enter a number that is the largest power of 2 less than or equal to n.

Use your pow2() function to find the correct answer.

Check if users answer is correct or not

If so, add 1 to their score

If not, tell them the correct answer.

Repeat these steps until the user types "stop" in place of a number.

If the user types "stop", your program should print out their final score and finish.

Sample Output (user input is highlighted)

Welcome to Power Quiz Game

Type 'stop' to exit

Score: 0

What number is the largest power of 2 that is less than or equal to 703? 512 Correct!

Score: 1

What number is the largest power of 2 that is less than or equal to 1925? 1024 Correct!

Score: 2

What number is the largest power of 2 that is less than or equal to 3377? 1024

Wrong! The correct answer is 2048

What number is the largest power of 2 that is less than or equal to 847? 500

Wrong! The correct answer is 512

What number is the largest power of 2 that is less than or equal to 2022? 1024

Correct!

Score: 3

What number is the largest power of 2 that is less than or equal to 1118? 999

Wrong! The correct answer is 1024

What number is the largest power of 2 that is less than or equal to 1567? 1024

Correct!

Score: 4

What number is the largest power of 2 that is less than or equal to 2271?

stop Your final score is 4

use python

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