From d255275919ab5ce020073ba0f34c56277b553554 Mon Sep 17 00:00:00 2001 From: Nick Chambers Date: Sat, 8 Oct 2022 23:15:57 -0500 Subject: [PATCH] Implement the game of bagels --- solution-1.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 solution-1.py diff --git a/solution-1.py b/solution-1.py new file mode 100755 index 0000000..25b0be6 --- /dev/null +++ b/solution-1.py @@ -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