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...
Your (turtle) program in python must include: Create four Red turtles and four Blue turtles using...
Your (turtle) program in python must include: Create four Red turtles and four Blue turtles using one or more lists. • Start each of the Red turtles at a different random location on the left side of the screen within the range of the square formed by (-100, 100) and (0, -100) and each of the Blue turtles at a random location on the right side of the screen within the range of the square formed by (0, 100) and...
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...
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...
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...
Python Program : simplist form and include comments Shopping Data by Zip Code Have you ever...
Python Program : simplist form and include comments Shopping Data by Zip Code Have you ever noticed that some stores ask you for your zip code before “ringing up” your transaction? Suppose you have been given three (3) text files (named kroger.txt, publix.txt, and ingles.txt) from popular grocery stores, containing zip codes of customers at each store. Additionally, you have been given a file named zipDirectory.txt which contains the zip code and city name (each on its own line). This...
Using Tkinter for GUI, A Python program that will allow the user to perform (i) generate...
Using Tkinter for GUI, A Python program that will allow the user to perform (i) generate RSA keys, (ii) encrypt a given message and (iii) decrypt the message without using any cryptographic library. Your program will generate the values of p unless the user provides them manually. Then the program will generate the keys (private and public). Then the program will allow the user to enter his/her message to be encrypted. Finally, the program will perform the decryption operation as...
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....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT