Question

In: Computer Science

The code that creates this program using Python: Your program must include: You will generate a...

The code that creates this program using Python:

  • Your program must include:

  • You will generate a random number between 1 and 100
  • You will repeatedly ask the user to guess a number between 1 and 100 until they guess the random number.
  • When their guess is too high – let them know
  • When their guess is too low – let them know
  • If they use more than 5 guesses, tell them they lose, you only get 5 guesses. And stop the game.
  • When they win, let them know how many guesses it took them

Solutions

Expert Solution

Explanation:

Here is the code which generates a random number from 1 to 100, and then keep asking the user to guess that number until either user guesses it correctly or user reaches the limit of guessing , that is 5 times.

Code:


import random

n = random.randint(1, 101)
guesses = 0

while(True):
  
guess = int(input("Enter guess: "))
  
guesses = guesses + 1
  
if(guess<n):
print("Too low!")
elif (guess>n):
print("Too high!")
else:
break
  
if(guesses==5):
print("You lose! You only get 5 guesses.")
break

if guesses<5:
print("You Win! You took", guesses, "guesses")

Output:

PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!


Related Solutions

The coding for this program to run as described on Python: Your (turtle) program must include:...
The coding for this program to run as described on Python: Your (turtle) program must include: include import turtle on a line after the comments so you can use the various Turtle-related objects and methods. Create a turtle named after your favorite ice cream flavor. Make sure the name has no punctuation and consists only of letters, numbers and the underscore character. Write your python program so your turtle is constantly moving and can be turned left and right using...
python code You are to write a program which produces a triangle as seen below. •Include...
python code You are to write a program which produces a triangle as seen below. •Include a function named goingUpwhich accepts a value and prints lines of stars beginning at 1 star and ending at the number of stars which was sent to it. For example, if the value sent to it is 4, the function would print this:********** •Include a function named goingDown which accepts a value and prints lines of stars beginning at 1 LESS THAN the value...
Using Python code create a program only with beginners code. You are taking online reservations at...
Using Python code create a program only with beginners code. You are taking online reservations at the The inn Ask for your client’s name and save in a variable Ask how many nights your client will be staying and save in a variable Room rental is $145 per night Sales tax is 8.5% Habitation tax is $5 per night (not subject to sales tax) Print out: Client’s name Room rate per night Number of nights Room cost (room rate *...
Please write in Python code please Write a program that creates a dictionary containing course numbers...
Please write in Python code please Write a program that creates a dictionary containing course numbers and the room numbers of the rooms where the courses meet. The dictionary should have the following key-value pairs: Course Number (key) Room Number (value) CS101 3004 CS102 4501 CS103 6755 NT110 1244 CM241 1411 The program should also create a dictionary containing course numbers and the names of the instructors that teach each course. The dictionary should have the following key-value pairs: Course...
Program must use Python 3 Your program must have a welcome message for the user. Your...
Program must use Python 3 Your program must have a welcome message for the user. Your program must have one class called CashRegister. Your program will have an instance method called addItem which takes one parameter for price. The method should also keep track of the number of items in your cart. Your program should have two getter methods. getTotal – returns totalPrice getCount – returns the itemCount of the cart Your program must create an instance of the CashRegister...
solve using r, include code in your answer (a) Generate 25 variables, each of which consists...
solve using r, include code in your answer (a) Generate 25 variables, each of which consists of 25 random samples from a standard normal. Store these variables in a data frame – call it df.train – and randomly select one variable to be the response – rename it y. (The end result should be a data frame with 25 observations on 25 variables but with no relationships between any of the variables.)Now  Repeat the same steps  to create a test set called...
In python make a simple code. You are writing a code for a program that converts...
In python make a simple code. You are writing a code for a program that converts Celsius and Fahrenheit degrees together. The program should first ask the user in which unit they are entering the temperature degree (c or C for Celcius, and f or F for Fahrenheit). Then it should ask for the temperature and call the proper function to do the conversion and display the result in another unit. It should display the result with a proper message....
(CODE IN PYTHON) Program Input: Your program will display a welcome message to the user and...
(CODE IN PYTHON) Program Input: Your program will display a welcome message to the user and a menu of options for the user to choose from. Welcome to the Email Analyzer program. Please choose from the following options: Upload text data Find by Receiver Download statistics Exit the program Program Options Option 1: Upload Text Data If the user chooses this option, the program will Prompt the user for the file that contains the data. Read in the records in...
Please write in beginner level PYTHON code! Your job is to write a Python program that...
Please write in beginner level PYTHON code! Your job is to write a Python program that asks the user to make one of two choices: destruct or construct. - If the user chooses to destruct, prompt them for an alternade, and then output the 2 words from that alternade. - If the user chooses construct, prompt them for 2 words, and then output the alternade that would have produced those words. - You must enforce that the users enter real...
#python. Explain code script of each part using comments for the reader. The code script must...
#python. Explain code script of each part using comments for the reader. The code script must work without any errors or bugs. Ball moves in a 2D coordinate system beginning from the original point (0,0). The ball can move upwards, downwards, left and right using x and y coordinates. Code must ask the user for the destination (x2, y2) coordinate point by using the input x2 and y2 and the known current location, code can use the euclidean distance formula...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT