So I'm trying out the Bagels Pico Fermi game, but I'm trying to write the code without looking to learn.
https://inventwithpython.com/bigbookpython/project1.html
I've written and rewritten this code at least 10 times, and as far as I can tell, the logic makes sense. However, whenever running the code and guessing, I either get all "Bagels" or one Fermi and 2 Bagels.
I am VERY new to python, so I am not really sure what to look up to fix this without just directly copying the working code from the sample.
print('Welcome to Bagels! The Deductive Logic Game!')
print('''The rules are simple,
Pico: The digit is correct but in the wrong position.
Fermi: The digit is correct and in the right position.
Bagels: The digit is not correct.
''')
print('You have 10 guesses to guess the secret 3 digit number, what is your first guess?')
import random
secretint = random.randint(1, 999)
secret = str(secretint).zfill(3)
print(secret)
guesses = 0
while guesses <= 10:
guess = str(input())
# guess is equal to secret
if guess == secret:
print('VICTORY')
exit()
else:
guesses += 1
digit1 = secret[:1]
digit2 = secret[:2]
digit3 = secret[:3]
guess1 = guess[:1]
guess2 = guess[:2]
guess3 = guess[:3]
if guess1 != digit1 and (guess1 == (digit2 or digit3)):
print('Pico')
else:
if guess1 == digit1:
print('Fermi')
else:
print('Bagels')
if guess2 != digit2 and (guess2 == (digit1 or digit3)):
print('Pico')
else:
if guess2 == digit2:
print('Fermi')
else:
print('Bagels')
if guess3 != digit3 and (guess3 == (digit1 or digit2)):
print('Pico')
else:
if guess3 == digit3:
print('Fermi')
else:
print('Bagels')
if guesses <= 11:
print('Out of guesses, goodbye!')