Implement the game of bagels
This commit is contained in:
parent
1ec7de7284
commit
d255275919
|
@ -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
|
Loading…
Reference in New Issue