Question

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.

Homework Answers

Answer #1
import random

number = random.randint(1, 100)

guess = -1
count = 0
while guess != number:
    guess = int(input('enter number to be guessed:'))
    count += 1
    if guess < number:
        print("Too low")
    elif guess > number:
        print("Too high")
print("you entered {}, and it took the program {} iterations to guess.".format(guess, count))

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 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.
Write a script that plays a simple “guess the number” game with the user. It should...
Write a script that plays a simple “guess the number” game with the user. It should select a random integer in the range [0 - 10], ask the user to guess the value, and provide feedback of the form “too high”, “too low”, or “congratulations” as appropriate. After the correct value is guessed, the script should terminate.
Write a program in Java where a user of this program will play a game in...
Write a program in Java where a user of this program will play a game in which he/she needs to guess a target number, which is a number that the program has randomly picked in the range that the user chooses. The program will repeatedly prompt for the guessed number and provide a clue whether the guessed number is bigger or smaller than the target number, until the guessed number equals the target number.
IN PYTHON : Write a program that asks the user for a number. Write the number...
IN PYTHON : Write a program that asks the user for a number. Write the number to a file called total.txt. Then ask the user for a second number. Write the new number on line 2 with the total for both numbers next to it separated by a comma. Then ask the user for a third number and do the same. Keep asking for numbers until the person puts in a zero to terminate the program. Close the file. Be...
- Write a Python program which asks the user to enter a number, if the number...
- Write a Python program which asks the user to enter a number, if the number is divisible by 6 or 7, the program prints “The number X is divisible by 6 or 7” and if the number is neither divisible by 6 nor by 7, then it prints “The number X is not divisible by 6 and 7”.
Write a Python program which calculates the average of the numbers entered by the user through...
Write a Python program which calculates the average of the numbers entered by the user through the keyboard. Use an interactive loop and ask the user at each iteration if he/she wants to enter more numbers. At the end dispay the average on the screen. Using built-in library functions for finding average is not allowed. Sample output of the program: Enter a number > 23 More numbers (yes or no)? y Enter a number > 4 Do you have more...
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...
Write a python program that does the following: Prompts the user for three numbers in one...
Write a python program that does the following: Prompts the user for three numbers in one request. Be sure to specify the “delimiter” by which a user enters those three numbers. Divides the first number by the second number and add that result to the third number. Prints output that shows in one line the formula applied and the result of the calculation. Validate input by: •    Checking the user entered 3 values •    Appropriately checking for the following errors:...
This is a very short trivia game. See if the user can guess the year that...
This is a very short trivia game. See if the user can guess the year that MDC (formerly Dade County Junior College) first started offering classes (1960). If the user guesses incorrectly, ask if they want another attempt. Once the user gets it right, report the number of guesses needed and end the program. Initial Output: MDC was originally named Dade County Junior College. Output (per loop) In what year were classes first offered? [user types: 1980] That answer is...
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...