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

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

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

  • Can someone please rewrite this code using a while loop? Please write it in python. #The...

    Can someone please rewrite this code using a while loop? Please write it in python. #The winning number my_number = 12 #variable for the input name user_n = input("Hello! What is your name?") #Ask the user print("Well",user_n,": I am thinking of a number between 1 and 20." + "Take a guess.") user_n = float(input("Take a guess.")) #if statements if user_n == my_number: print("Good job" ,user_n, "You guessed my number!") if user_n > my_number: print("Your guess is high. You lose.") if...

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
ADVERTISEMENT