Implement the game of bagels

This commit is contained in:
Nick Chambers 2022-10-08 23:15:57 -05:00
parent 1ec7de7284
commit d255275919
1 changed files with 31 additions and 0 deletions

31
solution-1.py Executable file
View File

@ -0,0 +1,31 @@
#!/usr/bin/env python3
import random
MAX_GUESSES = 10
def someint():
return random.randint(0, 9)
answer = [ someint(), someint(), someint() ]
attempt = 0
while attempt < MAX_GUESSES:
guess = input(f"Guess #{attempt + 1}: ")
digits = list(map(int, [ guess[0], guess[1], guess[2] ]))
result = [ ]
for idx in range(len(digits)):
if digits[idx] == answer[idx]:
result.append("fermi")
elif digits[idx] in answer:
result.append("pico")
else:
result.append("bagels")
print(" ".join(result))
if digits == answer:
attempt = MAX_GUESSES
else:
attempt += 1