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.
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...
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...
Using python, write the program below. Program Specifications: You are to write the source code and...
Using python, write the program below. Program Specifications: You are to write the source code and design tool for the following specification: A student enters an assignment score (as a floating-point value). The assignment score must be between 0 and 100. The program will enforce the domain of an assignment score. Once the score has been validated, the program will display the score followed by the appropriate letter grade (assume a 10-point grading scale). The score will be displayed as...
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...
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...
Please write the code in Python. Write a program/function in any Object-Oriented programming language that will...
Please write the code in Python. Write a program/function in any Object-Oriented programming language that will implement Queue Abstract Data Type with the following functions/methods.  Any build-in/pre-defined Queue function/library (e.g., java.util.Queue in Java) is NOT allowed to use in your code. push(Element):  insert the input Element (e.g., String or Integer in Java) to the end of the queue. pop(): remove the head element of the queue and print the head element on screen. count():  return the total number of elements in the queue...
Using Python, write the following code. You are to allow the user to enter the daily...
Using Python, write the following code. You are to allow the user to enter the daily temperature as a floating-point number. You should make the assumption that you are recording temperatures in Fahrenheit. You should allow the user to continue entering temperatures until the value -999 is entered. This number should not be considered a temperature, but just a flag to stop the program. As the user enters a temperature, you should display the following each time: Current Temperature: 999...