From 8b2f9a291a1f194f7987dad203870f8a744cc2ac Mon Sep 17 00:00:00 2001 From: deadvey Date: Fri, 15 Nov 2024 16:23:23 +0000 Subject: [PATCH] s&m --- bases-game.py | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/bases-game.py b/bases-game.py index b8ef82f..7409fcc 100644 --- a/bases-game.py +++ b/bases-game.py @@ -17,10 +17,46 @@ while True: Binary Addition Floating point binary - Twos compliment, Sign & Magnitude, Complex binary + Twos compliment, + Sign & Magnitude, ''' - type_int = random.randint(0,3) + type_int = random.randint(0,4) + if type_int == 4: + start_base = random.randint(0,1) + number_int = random.randint(0,128) + number_bin = format(number_int, '#010b')[2:] + if random.randint(0,1) == 1: # 50/50 chance of being negative + number_int = 0 - number_int + number_bin = '1' + number_bin[1:] + if start_base == 0: # Binary -> Denery + print("\nWhat is this Sign and Magnitude base 2 number in base 10?\n") + print(number_bin) + print("") + print("-") + print("|100") + print("||10") + print("|||1") + print("||||") + print("VVVV") + answer = str(int(number_int)) + elif start_base == 1: # Denery -> Binary + print("\nWhat is this base 10 number in Sign and Magnitude base 2?\n") + print(number_int) + print("") + print("-") + print("|64") + print("||32") + print("|||16") + print("||||8421") + print("||||||||") + print("VVVVVVVV") + answer = str(int(number_bin)) + attempt = input() + if int(attempt) == int(answer): + correct() + else: + print(f"No, the answer was {answer}") if type_int == 3: start_base = random.randint(0,1) positive_int = random.randint(0,127)