Question

In: Computer Science

Python: You will modify the given code to create a guessing game that takes user input...

Python:

You will modify the given code to create a guessing game that takes user input and allows you to make multiple guesses. There should also be a loop

Use the following attached Sample Code as a guide.

There are mistakes in the code!!!

#Guessing Game
import random
number=random.randint(1, another number)
print("Hello, CIS 101")
print("Let's play a guessing Game!called guess my number.")
print("The rules are: ")
print("I think of a number and you'll have to guess it.")
guess = random.randint(1, 5)
print("You will have " + str(guess) + " guesses.")
YourNumber = ???
unusedguesses=int(guess)
while unusedguesses < guess:
if int(YourNumber) == number:
print("YAY, You have guessed my number")
else:
unusedguesses=int(guess)-1
if unusedguesses == 0:
break
else:
print("Try again!")
print("The number was ", str(number))

Solutions

Expert Solution

main.py :

#Guessing Game
import random
number=random.randint(1, 100) #used to generate random number
print("Hello, CIS 101")
print("Let's play a guessing Game!called guess my number.")
print("The rules are: ")
print("I think of a number and you'll have to guess it.")
guess = random.randint(1, 5) #generating number of guesses
print("You will have " + str(guess) + " guesses.")
unusedguesses=0
#checking unusedguesses with guess
while unusedguesses < guess:
#asking user to enter guess
YourNumber =int(input("Enter a guess : "))
if int(YourNumber) == number: #checking guess
print("YAY, You have guessed my number")
else:
#increment the guess
unusedguesses=unusedguesses+1
if unusedguesses == 0:
break #break the loop
else:
print("Try again!")
#when the number is guessed
print("The number was ", str(number))

Screen for indentation :

=================================

Screen 1:


Related Solutions

Write a program using Python that allows the user to play a guessing game (please provide...
Write a program using Python that allows the user to play a guessing game (please provide a picture of code so it is easier to read). The game will choose a "secret number", a positive integer less than 10000. The user has 10 tries to guess the number. Requirements: Normally, we would have the program select a random number as the "secret number". However, for the purpose of testing your program (as well as grading it), simply use an assignment...
using xsd, Create a number guessing game You would need an input box and buttons Ask...
using xsd, Create a number guessing game You would need an input box and buttons Ask the user for a number Produce a random number from 1-50 Do the comparison ​a. Make sure to provide hints back to the user if the number enter is low or high ​​-this element should be automatically added ​b. Clear the value enter in the text ​c. Give them 3 tries Whether the user wins or loses, display all the guesses along with the...
using xml, Create a number guessing game You would need an input box and buttons Ask...
using xml, Create a number guessing game You would need an input box and buttons Ask the user for a number Produce a random number from 1-50 Do the comparison             a. Make sure to provide hints back to the user if the number enter is low or high                         -this element should be automatically added             b. Clear the value enter in the text             c. Give them 3 tries Whether the user wins or loses, display all the...
C++ The program implements the Number Guessing Game. However, in that program, the user is given...
C++ The program implements the Number Guessing Game. However, in that program, the user is given as many tries as needed to guess the correct number. Rewrite the program so that the user has no more than five tries to guess the correct number. Your program should print an appropriate message, such as “You win!” or “You lose!”.
(Python code please) Of a Guessing game(1-10) with a limited amount of guesses (5)
(Python code please) Of a Guessing game(1-10) with a limited amount of guesses (5)
In JAVA Create a simple guessing game, similar to Hangman, in which the user guesses letters...
In JAVA Create a simple guessing game, similar to Hangman, in which the user guesses letters and then attempts to guess a partially hidden phrase. Display a phrase in which some of the letters are replaced by asterisks: for example, G* T*** (for Go Team). Each time the user guesses a letter, either place the letter in the correct spot (or spots) in the phrase and display it again or tell the user the guessed letter is not in the...
in java Create simple number guessing game as follows. First, prompt the user to enter a...
in java Create simple number guessing game as follows. First, prompt the user to enter a min and max value. In your code, declare and assign a variable with a random integer in this range (inclusive). Then, ask the user to guess the number. Input the user's guess. And at the end output "Correct!" if the user's guess was right on spot, or "Sorry, the answer is not corrcet.” The number I was looking for was xxx. Replace xxx with...
guessing game in Java. It will have a guess input used for guessing the random number...
guessing game in Java. It will have a guess input used for guessing the random number that is generated from 1 - 100. When the user makes a guess it will tell them if the number is lower or higher than the guess. There is also a choice to give up which then reveals the correct number. The last choice will be new game which resets the random number. Last, the program should keep counts of tries. When the user...
You are asking to develop a “Triangle Guessing” game in Python for the assignment. The program...
You are asking to develop a “Triangle Guessing” game in Python for the assignment. The program accepts the lengths of three (3) sides of a triangle as input from a player. The program output should indicate whether the triangle is a right triangle, an acute triangle, or an obtuse triangle. 1.Tips to help you for this assignment: Make sure each side of the triangle is a positive integer. Use try/except for none positive integer input. 2. Validating the triangle. That...
Answer in Python: show all code 3) Modify your code to take as input from the...
Answer in Python: show all code 3) Modify your code to take as input from the user the starting balance, the starting and ending interest rates, and the number of years the money is in the account. In addition, change your code (from problem 2) so that the program only prints out the balance at the end of the last year the money is in the account. (That is, don’t print out the balance during the intervening years.) Sample Interaction:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT