Question

****CODE IN PYTHON***** (Please replicate it EXACTLY as it is shown in the sample run) Write...

****CODE IN PYTHON***** (Please replicate it EXACTLY as it is shown in the sample run)

Write a program where the user and the program/computer play a number guessing game. The program should prompt the user for a number (between 1 and 100, inclusive) then the program/computer has to guess what the user entered. Keep track of the number of iterations it takes for the computer to guess the number. Sample runs are shown below:

Enter number to be guessed: 88

You entered 88, and it took the program 3 iterations to guess

Enter number to be guessed: 55

You entered 55, and it took the program 19 iterations to guess

Homework Answers

Answer #1

import random

n=int(input("Enter number to be guessed:"))

if(n>=1 and n<=100):

cnt=1

while(True):

generated_value=random.randint(1,100)

if(n==generated_value):

print("You entered {}, and it took the program {} iterations to guess".format(n,cnt))

break

else:

cnt=cnt+1

else:

pass

kindly follow indentation as per the above screenshoot othwrwise python raises indentation error

#updated take input 2 times:

import random

check=0

while(check!=2):

n=int(input("Enter number to be guessed:"))

if(n>=1 and n<=100):

cnt=1

while(True):

generated_value=random.randint(1,100)

if(n==generated_value):

print("You entered {}, and it took the program {} iterations to guess".format(n,cnt))

break

else:

cnt=cnt+1

check=check+1

else:

pass

Know the answer?
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
Similar Questions
Write a Python program that plays a number guessing game with a human user. The human...
Write a Python program that plays a number guessing game with a human user. The human user will think of a number between 1 and 100, inclusive. Then the program has to guess what the user entered. keep track of the number of interaction it takes for the computer to guess the number. sample run: enter number to be guessed:88 output: you entered 88, and it took the program 3 iterations to guess.
Write a program that plays a number guessing game with a human user. The human user...
Write a program that plays a number guessing game with a human user. The human user will think of a number between 1 and 100, inclusive. Then the program has to guess what the user entered. keep track of the number of interaction it takes for the computer to guess the number. sample run: enter number to be guessed:88 output: you entered 88, and it took the program 3 iterations to guess.
use repl.it intro to C-programing no advance code also put good comment that i can know...
use repl.it intro to C-programing no advance code also put good comment that i can know whats this code use for  thank you use repl.it intro to C-programing no advance code also put good comment that i can know whats this code use for  thank you program for a game of hangman. Store the word to be guessed as individual characters of an array called word. The player must guess the letters belonging to word. If the user enters a valid letter,...
Python code only! (Do not include breaks or continue functions) Write a program that asks the...
Python code only! (Do not include breaks or continue functions) Write a program that asks the user to enter the amount that they budgeted for the month. A loop should then prompt the user to enter their expenses, one at a time and to enter 0 to quit. When the loop finishes, the program should display the the amount of budget left. (a negative number indicates the user is over budget and a positive number indicates the user is under...
Please use Python 3 4). Write a program that asks the user to enter 10 numbers....
Please use Python 3 4). Write a program that asks the user to enter 10 numbers. The program should store the numbers in a list and then display the following data: • The lowest number in the list • The highest number in the list •The total of the numbers in the list • The average of the numbers in the list   Sample input & output: (Prompt) Enter Number 1: (User enter) 4 (Prompt) Enter Number 2: (User enter) 7...
Create a very simple TCP Application in JAVA. You will create a client and a server....
Create a very simple TCP Application in JAVA. You will create a client and a server. The client must execute after you start the server. Here is what they will do. The client will read from the console a string that the users enters. This string will be the name of the user, let's say Bob. The client then sends the name, Bob, in an Object Stream, to the server. The server will receive this Object Stream and send to...
Goal: Write a simple number guessing game in java. The game picks a number between bounds...
Goal: Write a simple number guessing game in java. The game picks a number between bounds input by the user, then user has to guess the number. The game will tell you if your guess is too high or too low. When you guess it, the game will tell you how many guesses it took Run multiple games and print statistics (# games, # guesses, avg) when all done. Sample Run: G U E S S I N G G...
The following code to run as the described program on python. The extra test file isn't...
The following code to run as the described program on python. The extra test file isn't included here, assume it is a text file named "TXT" with a series of numbers for this purpose. In this lab you will need to take a test file Your program must include: Write a python program to open the test file provided. You will read in the numbers contained in the file and provide a total for the numbers as well as the...
Write a Python program that splits, doubles, and reverse each input string entered. For each string,...
Write a Python program that splits, doubles, and reverse each input string entered. For each string, split it at the given integer, and then output it in format as shown below. Convert all stings entered to uppercase for output. Assume string length is greater than the split value. Refer to the sample output below. Sample Runs: Enter a string: holiday Enter the number to split on: 3 HOL-YADI-LOH-IDAY Enter a string: TATTARRATTAT Enter the number to split on: 6 TATTAR-TATTAR-RATTAT-RATTAT...
NOTE:- PLEASE USE THE INSTRUCTION ACCORDING TO "CHAPTER 3" OF "STARTING OUT WITH PYTHON 4TH EDITION"...
NOTE:- PLEASE USE THE INSTRUCTION ACCORDING TO "CHAPTER 3" OF "STARTING OUT WITH PYTHON 4TH EDITION" PROGRAM 3_1:- Write a program that determines the cost of online order of T-shirts. T-shirts are priced at $12.99 each, but discounts are applied for quantities as follows: - 12 or more shirts earn a 30% discount and free shipping - 6-11 shirts earn a 20% discount - and 3-5 shirts earn a 10% discount - 1 or 2 shirts, no discounts Prompt the...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • c = 100 + 0.8 (y - t) i = 500 - 50r g = 400...
    asked 8 minutes ago
  • When we observe two charged balloons dangling from thin thread, they can repel each other. We...
    asked 27 minutes ago
  • I study management information systems in my fourth year, but I do not know anything about...
    asked 27 minutes ago
  • What features of the environment are people “wired” to detect? Why? Would it be adaptive for...
    asked 28 minutes ago
  • Graduates of fashion marketing group men 8 women 20 have chosen work in France, probability of...
    asked 39 minutes ago
  • Despite guidelines regulating eligibility for special education services, today’s special education classrooms continue to be over   populated...
    asked 1 hour ago
  • A. Find the sum 3+8+13+...+28 B.  Find the first term and the common difference of the arithmetic...
    asked 1 hour ago
  • Explain why in a multiplier model a rise in household wealth relative to target will ceteris...
    asked 1 hour ago
  • What political and economic roles have Japan and the United States played in Southeast Asia in...
    asked 1 hour ago
  • What does the function split do? Explain with an example. ​ ​ def split(L, first): return...
    asked 1 hour ago
  • Code a simple Editor class with 2 constructors (one default, one with a string for a...
    asked 1 hour ago
  • Using a greedy algorithm solve the following instance of Interval Scheduling {(2,12),(1,7),(3,5),(8,10),(7,14),(9,16),(10,14),(12,13),(17,22),(13,14),(15,20),(14,18),(20,30),(22,25),(26,27),(25,29),(24,31)}
    asked 1 hour ago