Thursday, March 7, 2019

Dylan Nguyen PM Open Lab Friends Guessing Game PT 5

Yesterday I was working on my Friends Guessing Game. Today I was still working on it because it had a problem with the winner statement. When the player guess the name correctly, the computer will say that they won but will also say that they lost. For example, the computer takes a name from the Friends list i created (Phoebe, Rachel, Ross, Joey, Monica and Chandler) and say the computer picks Monica. The player takes a guess and type Monica and gets it correctly, stating how many tries the player did it in and being told that they won. However, the computer jumps to the if statement I put after, saying that they lost. So the computer says that they won in blank many tries and then suddenly says that they lost. What I found out is to do a little of deletion. I deleted the if statement that I put was after the else statements. This way, the player can be acknowledge as one or the other rather than both. When looking at the 2, pay attention to the bottom of the description codes. Test both and you will be able to identify the difference. 

This is Before:

#guessing name game
#!= means is not
#guessing tries += 1 every try
import random
secret_name = ['Monica','Rachel','Chandler','Joey','Phoebe','Ross']
rand_secret_name = secret_name[random.randrange(len(secret_name))]
guess = ""
guess_count = 0
guess_limit = 3
out_of_guesses = False
print("you get 2 tries!")

while guess != secret_name and not(out_of_guesses):
    if guess_count < guess_limit:
        guess = input("Guess the name: ")
        guess_count += 1
        if guess == secret_name[random.randrange(len(secret_name))]:
            print("correct")
            print ("Did it in", guess_count)
            out_of_guesses = True
        elif guess == "Monica":
            print("not her, try again")
        elif guess == "Rachel":
            print("Ain't the spoil one")
        elif guess == "Chandler":
            print("Not the funny one")
        elif guess == "Joey":
            print("Not actor")
        elif guess == "Phoebe":
            print("doesn't play the guitar")
        elif guess == "Ross":
            print("Aint the dinosaur dude")
       
        else:
            print("someone IN friends")

    else:
        out_of_guesses = True
   
if out_of_guesses:
     print("out of guesses, you lost boi! It's " )
else:
    print("you won!")



This is Today:

#guessing name game
#!= means is not
#guessing tries += 1 every try
import random
secret_name = ['Monica','Rachel','Chandler','Joey','Phoebe','Ross'] 
rand_secret_name = secret_name[random.randrange(len(secret_name))]
guess = ""
guess_count = 0
guess_limit = 3
out_of_guesses = False
print("you get 3 tries!")

while guess != secret_name and not(out_of_guesses):
    if guess_count < guess_limit:
        guess = input("Guess the name: ")
        guess_count += 1
        if guess == secret_name[random.randrange(len(secret_name))]:
            print("correct")
            print ("Did it in", guess_count)
            out_of_guesses = True
        elif guess == "Monica":
            print("not her, try again")
        elif guess == "Rachel":
            print("Ain't the spoil one")
        elif guess == "Chandler":
            print("Not the funny one")
        elif guess == "Joey":
            print("Not actor")
        elif guess == "Phoebe":
            print("doesn't play the guitar")
        elif guess == "Ross":
            print("Aint the dinosaur dude")
        else:
            print("someone IN friends")

    else:
        out_of_guesses = True
        print("failure")
       
                 
 





No comments:

Post a Comment