Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program called pyramid.py that uses nested loops to draw the pattern below. Your solution must use nested loops and must use calls to

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Write a program called pyramid.py that uses nested loops to draw the pattern below. Your solution must use nested loops and must use calls to print("*", end="") and print(" ", end="") to print characters to the screen (without moving to the next line) and calls to print() to move down to the next line (you are not allowed to use any of the formatting functions). Write and test a function called pow2(m) that takes one (positive) number m as input and returns the largest power of 2 that's less than or equal to that number. Some examples include: pow2(2) pow2(12) pow2(20) pow2(284) 2 8 16 256 Problem 3 (Taking User Input) Write a function called userGuess(n) that takes an integer n as an argument. This function should display n to the user and prompt them to enter the number num that is the largest power of 2 less than or equal to n. Have your function return the user's input num (it will be used in the next problem) 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 Use your pow20 function to find the correct answer. Check if user's 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

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 Internals A Deep Dive Into How Distributed Data Systems Work

Authors: Alex Petrov

1st Edition

1492040347, 978-1492040347

More Books

Students also viewed these Databases questions