Question

FIX CODE-- import random number=random.randint ('1', 'another number') print("Hello, CIS 101") print("Let's play a guessing Game!called...

FIX CODE--

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))

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Modified code (Python):

import random

number=random.randint (1,5) #Instead of (1,5) You can put any range {(User must guess this number)}

print("Hello, CIS 101")

print("Let's play a guessing Game!called guess my number.") #Game starts

print("The rules are: ")

print("I think of a number and you'll have to guess it.")

guess = random.randint(1, 5) #Number of guesses

print("You will have " + str(guess) + " guesses.")

unusedguesses=int(guess)

while unusedguesses != 0: #While the number of guesses not equals to Zero

try: #try and except block (if the user enters a character or a string)

YourNumber = input("Guess your number : ") #Prompting the user to input a number

if int(YourNumber) == number: #If the user guesses the number correctly

print("YAY, You have guessed my number\n")

break

else:

unusedguesses -= 1 #Decrementing the number of guesses

if unusedguesses == 0:

break

else:

print("Try again!\n")

except: #Except block for, if the user inputs other than a integer

unusedguesses -= 1

if unusedguesses !=0 :

print("Try again (Guessing number must be an integer)\n")

pass

print("The number was ", str(number)) #Finally printing our required number

#END OF THE CODE

CODE IMPLEMENTATION:

TESTING OUTPUT 1 (If the user enters only integers):

TESTING OUTPUT 2 (If the user enters characters or strings):

NOTE: I have used a try and except block in the code because, if the user enters a "string" or a "character" other than an "integer" the previous code given will throw an error....So to overcome that situtation i have used a try and except block..

#Any questions or clarifications or modifications needed u can ask me in the comments section...:)

Add a comment
Know the answer?
Add Answer to:
FIX CODE-- import random number=random.randint ('1', 'another number') print("Hello, CIS 101") print("Let's play a guessing Game!called...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • on python i need to code a guessing game. After the player has guessed the random...

    on python i need to code a guessing game. After the player has guessed the random number correctly, prompt the user to enter their name. Record the names in a list along with how many tries it took them to reach the unknown number. Record the score for each name in another list. When the game is quit, show who won with the least amount of tries. this is what i have so far: #Guess The Number HW assignment import...

  • Can you please enter this python program code into an IPO Chart? import random def menu():...

    Can you please enter this python program code into an IPO Chart? import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the non-numbers #if user enters letters, then except will show the message, Numbers only! try: c=int(input("Enter your choice: ")) if(c>=1 and c<=3): return c else: print("Enter number between 1 and 3 inclusive.") except: #print exception print("Numbers Only!")...

  • Python Program Python: Number Guessing Game Write a Python function called "Guess.py" to create a number...

    Python Program Python: Number Guessing Game Write a Python function called "Guess.py" to create a number guessing game: 1. Function has one input for the number to Guess and one output of the number of attempts needed to guess the value (assume input number will always be between 1 and 1000). 2. If no number was given when the function was called, use random.randint(a,b) to generate a random number between a=1 and b=1000. You will also need to add an...

  • Java Guessing Game Class The class will generate a random number of 1 to 15, and...

    Java Guessing Game Class The class will generate a random number of 1 to 15, and then check to see if the user guessed the number correctly. If the number is incorrect, the user should have the chance to guess again, until they guess the right number or they guess 10 times. The class method should keep track of the number of guesses the user has had, and return this value.   The class should have one constructors, a default and...

  • Can you add code comments where required throughout this Python Program, Guess My Number Program, and...

    Can you add code comments where required throughout this Python Program, Guess My Number Program, and describe this program as if you were presenting it to the class. What it does and everything step by step. import random def menu(): #function for getting the user input on what he wants to do print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the...

  • Required in JAVA language Write a program that enables a user to play number guessing games....

    Required in JAVA language Write a program that enables a user to play number guessing games. The following is a nutshell description of a number guessing game. + a random number is generated + loop prompting the user to enter guesses until the user guesses the number or hits the maximum number of allowed guesses or enters the "quit" sentinel value The rest of this specification documents number guessing games in more detail. The documentation uses manifest constants that can...

  • Write a program that allows a user to play a guessing game. Pick a random number...

    Write a program that allows a user to play a guessing game. Pick a random number in between 1 and 100, and then prompt the user for a guess. For their first guess, if it’s not correct, respond to the user that their guess was “hot.” For all subsequent guesses, respond that the user was “hot”if their new guess is strictly closer to the secret number than their old guess and respond with“cold”, otherwise. Continue getting guesses from the user...

  • Lab #6 Number Guessing Game – Loops and Nested Loops Requirements: Design, develop, test, and submit a program for a Number Guessing game. The program will select a random number between 0 and 100, al...

    Lab #6 Number Guessing Game – Loops and Nested Loops Requirements: Design, develop, test, and submit a program for a Number Guessing game. The program will select a random number between 0 and 100, allow the user to try up to 10 times to guess the number, and tell the user if each guess is too high, too low, or correct. The actual game portion must be a function...you can use more than one function in your program. The amount...

  • Java Listed below is code to play a guessing game. In the game, two players attempt...

    Java Listed below is code to play a guessing game. In the game, two players attempt to guess a number. Your task is to extend the program with objects that represent either a human player or a computer player. boolean checkForWin (int guess, int answer) { System.out.println("You guessed" + guess +"."); if (answer == guess) { System.out.println( "You're right! You win!") ; return true; } else if (answer < guess) System.out.println ("Your guess is too high.") ; else System.out.println ("Your...

  • how would i write my code in Pseudocode? I am pretty much a beginner, therefore this...

    how would i write my code in Pseudocode? I am pretty much a beginner, therefore this is my first major computer science assignment and im not really understanding the written way of code.. please help and explain. Thank you! this is my working code: # Guess The Number HW assignment import random guessesTaken = 0 names=[] tries=[] print("Welcome! ") question = input("Would you like to play the guessing game? [Y/N]") if question == "N": print("Sorry to see you go so...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT