Untitled

 avatar
unknown
plain_text
9 hours ago
1.4 kB
16
Indexable
# guess a 3 

print('''Bagels, a deductive logic game.
By Al Sweigart [email protected]
      
I am thinking of a 3-digit number. Try to guess what it is.
Here are some clues:
When I say: That means:
 Pico   One digit is correct but in the wrong position.
 Fermi  One digit is correct and in the right position.
 Bagels No digit is correct
    
I have thought up a number.
You have 10 guesses to get it.''')


import random
def main():
    n = 3
    answer = random.randint(int('1' + '0'*(n-1)),int('9'*n))
    answer = str(answer)
    won = None

    for i in range(10):
        guess = input(f"Guess #{i+1}: ")

        while len(guess) !=n:
            print(f"Please Enter a {n}digit number")
            guess = input(f"Guess #{i+1}: ")
            

        display = []
        for j in range(n):
            if guess[j] == answer[j]:
                display.append('Fermi')
            elif guess[j] in answer:
                display.append('Pico')
            if display.count("Fermi") == n:
                print("U guessed it right u won!")
                won = True
        if not display:
            display = ["Bagles"]
        random.shuffle(display)      
        if won:
            break
        else:
            print(" ".join(display))  

    if not won:
        print("You Lost")
        
main()
ok = input("do u want to play again")

if ok == 'yes':
    main()
Editor is loading...
Leave a Comment