Question

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 random

guessesTaken = 0

print ("Welcome! ")


question = input ("Would you like to play the guessing game? [Y/N]")

if question == "N":
print ("Sorry to see you go so soon, bye for now!")
  
if question == "Y":
print("..loading..")
print("Well, I am thinking of a number between 1 and 20.")
  
number = random.randint(1,20)
#-------------------------------------------------------------------
while True:
while guessesTaken < 7 : #UNLIMITED GUESSES
print("Take a guess.")
guess = input ()
while (guess.isdigit()== False):
guess = input ("Guess needs to be a whole number.")
  
guess = int(guess)
  
guessesTaken = guessesTaken + 1
  
if guess < number:
print ("Your guess is too low.")
  
if guess > number:
print("Your guess is too high.")
  
if guess == number:
break
  
if guess == number:
guessesTaken = str(guessesTaken)
print("Good job, you guessed my number! What is your name?")
name = input("Enter name:")
  
if guess != number:
number = str(number)
print("Nope. The number I was thinking of was " + number)
  
question = input("Lets play again (press q to quit or enter to continue) ")
if (question == "q"):
print("goodbye.")
break
else:
print("Well, I am thinking of a number between 1 and 20.")
  
number = random.randint(1,20)

list.append(name)
list.append(guess)
print (guess.count)

0 0
Add a comment Improve this question Transcribed image text
Answer #1
# 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 soon, bye for now!")
else:
    print("..loading..")
    while question!='q':
        print("Well, I am thinking of a number between 1 and 20.")

        number = random.randint(1, 20)
        # -------------------------------------------------------------------
        guess = 21
        while guess != number and guessesTaken < 10:
            print("Take a guess.")
            guess = input()
            while (guess.isdigit() == False):
                guess = input("Guess needs to be a whole number.")
            guess = int(guess)
            guessesTaken = guessesTaken + 1
            if guess < number:
                print("Your guess is too low.")
            if guess > number:
                print("Your guess is too high.")

        if guess == number:
            print("Good job, you guessed my number! What is your name?")
            name = input("Enter name:")
            names.append(name)
            tries.append(guessesTaken)
        else:
            number = str(number)
            print("Nope. The number I was thinking of was " + number)

        question = input("\nLets play again (press q to quit or enter to continue) ")
        if (question == "q"):
            print("goodbye.")

minGuess=min(tries)
ind=tries.index(minGuess)
name=names[ind]
print()
print(name,'won with the least amount of tries',minGuess)

Add a comment
Know the answer?
Add Answer to:
on python i need to code a guessing game. After the player has guessed the random...
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
  • 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...

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

  • 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...

  • Write a JAVA program that plays a number guessing game with the user. A sample run...

    Write a JAVA program that plays a number guessing game with the user. A sample run for the game follows. User input is shown in boldface in the sample run. Welcome to the game of Guess It! I will choose a number between 1 and 100. You will try to guess that number. If your guess wrong, I will tell you if you guessed too high or too low. You have 6 tries to get the number. OK, I am...

  • 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...

  • 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...

  • 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!")...

  • This program will implement a simple guessing game... Write a program that will generate a random...

    This program will implement a simple guessing game... Write a program that will generate a random number between 1 and 50 and then have the user guess the number. The program should tell the user whether they have guessed too high or too low and allow them to continue to guess until they get the number or enter a 0 to quit. When they guess the number it should tell them how many guesses it took. At the end, the...

  • A Backwards Guessing Game For this assignment, you will be a making a guessing game with...

    A Backwards Guessing Game For this assignment, you will be a making a guessing game with a twist. You will play the role of the computer, and the computer will try to guess the number. You will think of a number (you don’t have to read it in as input) between 1 and 100. You will create a loop that runs 5 times. In this loop, the computer will try to guess the number in the range it knows is...

  • I need the create a Python code that makes a two-player Rock-Paper-Scissors game. (Hint: Ask for...

    I need the create a Python code that makes a two-player Rock-Paper-Scissors game. (Hint: Ask for player plays (using input), compare them, print out a message of congratulations to the winner, and ask if the players want to start a new game) Please help me see why my "continue" is asking the players to start a new game. Here is my code; user1= input("Whats your name? ") user2= input("And your name? ") a = input("%s, do yo want to choose...

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