Files
basic-computer-games/64_Nicomachus/python/nicomachus.py
2022-03-10 06:59:21 +01:00

79 lines
1.6 KiB
Python

"""
NICOMACHUS
Math exercise/demonstration
Ported by Dave LeCompte
"""
# PORTING NOTE
#
# The title, as printed ingame, is "NICOMA", hinting at a time when
# filesystems weren't even 8.3, but could only support 6 character
# filenames.
import time
def print_with_tab(spaces_count, msg):
if spaces_count > 0:
spaces = " " * spaces_count
else:
spaces = ""
print(spaces + msg)
def get_yes_or_no():
while True:
response = input().upper()
if response == "YES":
return True
elif response == "NO":
return False
print(f"EH? I DON'T UNDERSTAND '{response}' TRY 'YES' OR 'NO'.")
def play_game():
print("PLEASE THINK OF A NUMBER BETWEEN 1 AND 100.")
print("YOUR NUMBER DIVIDED BY 3 HAS A REMAINDER OF")
a = int(input())
print("YOUR NUMBER DIVIDED BY 5 HAS A REMAINDER OF")
b = int(input())
print("YOUR NUMBER DIVIDED BY 7 HAS A REMAINDER OF")
c = int(input())
print()
print("LET ME THINK A MOMENT...")
print()
time.sleep(2.5)
d = (70 * a + 21 * b + 15 * c) % 105
print(f"YOUR NUMBER WAS {d}, RIGHT?")
response = get_yes_or_no()
if response:
print("HOW ABOUT THAT!!")
else:
print("I FEEL YOUR ARITHMETIC IS IN ERROR.")
print()
print("LET'S TRY ANOTHER")
def main():
print_with_tab(33, "NICOMA")
print_with_tab(15, "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY")
print()
print()
print()
print("BOOMERANG PUZZLE FROM ARITHMETICA OF NICOMACHUS -- A.D. 90!")
print()
while True:
play_game()
if __name__ == "__main__":
main()