Formatted the output texts to follow a more modern style

This commit is contained in:
Gabry
2022-02-24 19:34:26 +01:00
parent 69944fecc1
commit 74ad6e9ea7

View File

@@ -1,7 +1,7 @@
from random import random
print("SLALOM".rjust(39))
print("CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n\n\n".rjust(57))
print("Slalom".rjust(39))
print("Creative Computing Morristown, New Jersey\n\n\n".rjust(57))
medals = {
"gold": 0,
@@ -19,64 +19,64 @@ def ask_int(question):
return int(reply) if reply.isnumeric() else -1
def pre_run():
print("\nTYPE \"INS\" FOR INSTRUCTIONS")
print("TYPE \"MAX\" FOR APPROXIMATE MAXIMUM SPEEDS")
print("TYPE \"RUN\" FOR THE BEGINNING OF THE RACE")
cmd = ask("COMMAND--")
print("\nType \"INS\" for instructions")
print("Type \"MAX\" for approximate maximum speeds")
print("Type \"RUN\" for the beginning of the race")
cmd = ask("Command--")
while cmd != "RUN":
if cmd == "INS":
print("\n*** SLALOM: THIS IS THE 1976 WINTER OLYMPIC GIANT SLALOM. YOU ARE")
print(" THE AMERICAN TEAM'S ONLY HOPE OF A GOLD MEDAL.\n")
print(" 0 -- TYPE THIS IS YOU WANT TO SEE HOW LONG YOU'VE TAKEN.")
print(" 1 -- TYPE THIS IF YOU WANT TO SPEED UP A LOT.")
print(" 2 -- TYPE THIS IF YOU WANT TO SPEED UP A LITTLE.")
print(" 3 -- TYPE THIS IF YOU WANT TO SPEED UP A TEENSY.")
print(" 4 -- TYPE THIS IF YOU WANT TO KEEP GOING THE SAME SPEED.")
print(" 5 -- TYPE THIS IF YOU WANT TO CHECK A TEENSY.")
print(" 6 -- TYPE THIS IF YOU WANT TO CHECK A LITTLE.")
print(" 7 -- TYPE THIS IF YOU WANT TO CHECK A LOT.")
print(" 8 -- TYPE THIS IF YOU WANT TO CHEAT AND TRY TO SKIP A GATE.\n")
print(" THE PLACE TO USE THESE OPTIONS IS WHEN THE COMPUTER ASKS:\n")
print("OPTION?\n")
print(" GOOD LUCK!\n")
cmd = ask("COMMAND--")
print("\n*** Slalom: This is the 1976 Winter Olypic Giant Slalom. You are")
print(" the American team's only hope for a gold medal.\n")
print(" 0 -- Type this if you want to see how long you've taken.")
print(" 1 -- Type this if you want to speed up a lot.")
print(" 2 -- Type this if you want to speed up a little.")
print(" 3 -- Type this if you want to speed up a teensy.")
print(" 4 -- Type this if you want to keep going the same speed.")
print(" 5 -- Type this if you want to check a teensy.")
print(" 6 -- Type this if you want to check a little.")
print(" 7 -- Type this if you want to check a lot.")
print(" 8 -- Type this if you want to cheat and try to skip a gate.\n")
print(" The place to use these options is when the Computer asks:\n")
print("Option?\n")
print(" Good Luck!\n")
cmd = ask("Command--")
elif cmd == "MAX":
print("GATE MAX")
print("Gate Max")
print(" # M.P.H.")
print("----------")
for i in range(0, gates):
print(f" {i + 1} {max_speeds[i]}")
cmd = ask("COMMAND--")
cmd = ask("Command--")
else:
cmd = ask(f"\"{cmd}\" IS AN ILLEGAL COMMAND--RETRY")
cmd = ask(f"\"{cmd}\" is an illegal command--Retry")
def run():
global medals
print("THE STARTER COUNTS DOWN...5...4...3...2...1...GO!")
print("The starter counts down...5...4...3...2...1...Go!")
time = 0
speed = int(random() * (18 - 9) + 9)
print("YOU'RE OFF")
print("You're off")
for i in range(0, gates):
while True:
print(f"\nHERE COMES GATE #{i + 1}:")
print(f" {int(speed)}M.P.H.")
print(f"\nHere comes gate #{i + 1}:")
print(f" {int(speed)} M.P.H.")
old_speed = speed
opt = ask_int("OPTION")
opt = ask_int("Option")
while opt < 1 or opt > 8:
if(opt == 0):
print(f"YOU'VE TAKEN {int(time)}SECONDS.")
print(f"You've taken {int(time)} seconds.")
else:
print("WHAT?")
opt = ask_int("OPTION")
print("What?")
opt = ask_int("Option")
if opt == 8:
print("***CHEAT")
print("***Cheat")
if random() < .7:
print("AN OFFICIAL CAUGHT YOU!")
print(f"YOU TOOK {int(time + random())}SECONDS.")
print("An official caught you!")
print(f"You took {int(time + random())} seconds.")
return
else:
print("YOU MADE IT!")
print("You made it!")
time += 1.5
else:
match opt:
@@ -97,69 +97,69 @@ def run():
case 7:
speed -= int(random() * (10 - 5) + 5)
print(f" {int(speed)}M.P.H.")
print(f" {int(speed)} M.P.H.")
if speed > max_speeds[i]:
if random() < ((speed - max_speeds[i]) * .1) + .2:
print(f"YOU WENT OVER THE MAXIMUM SPEED AND {'SNAGGED A FLAG' if random() < .5 else 'WIPED OUT'}!")
print(f"YOU TOOK {int(time + random())}SECONDS")
print(f"You went over the maximum speed and {'snagged a flag' if random() < .5 else 'wiped out'}!")
print(f"You took {int(time + random())} seconds")
return
else:
print("YOU WENT OVER THE NAXIMUM SPEED AND MADE IT!")
print("You went over the maximum speed and made it!")
if speed > max_speeds[i] - 1:
print("CLOSE ONE!")
print("Close one!")
if speed < 7:
print("LET'S BE REALISTIC, OK? LET'S GO BACK AND TRY AGAIN...")
print("Let's be realistic, ok? Let's go back and try again...")
speed = old_speed
else:
time += max_speeds[i] - speed + 1
if speed > max_speeds[i]:
time += .5
break
print(f"\nYOU TOOK {int(time + random())}SECONDS.")
print(f"\nYou took {int(time + random())} seconds.")
avg = time / gates
if avg < 1.5 - (lvl * .1):
print("YOU WON A GOLD MEDAL!")
print("Yout won a gold medal!")
medals["gold"] += 1
elif avg < 2.9 - (lvl * .1):
print("YOU WON A SILVER MEDAL!")
print("You won a silver medal!")
medals["silver"] += 1
elif avg < 4.4 - (lvl * .01):
print("YOU WON A BRONZE MEDAL!")
print("You won a bronze medal!")
medals["bronze"] += 1
while True:
gates = ask_int("HOW MANY GATES DOES THIS COURSE HAVE (1 TO 25)")
gates = ask_int("How many gates does this course have (1 to 25)")
if gates < 1:
print("TRY AGAIN,")
print("Try again,")
else:
if(gates > 25):
print("25 IS THE LIMIT.")
print("25 is the limit.")
break
pre_run()
while True:
lvl = ask_int("RATE YOURSELF AS A SKIER, (1=WORST, 3=BEST)")
lvl = ask_int("Rate yourself as a skier, (1=Worst, 3=Best)")
if lvl < 1 or lvl > 3:
print("THE BOUNDS ARE 1-3.")
print("The bounds are 1-3.")
else:
break
while True:
run()
while True:
answer = ask("DO YOU WANT TO PLAY AGAIN?")
answer = ask("Do you want to play again?")
if answer == "YES" or answer == "NO":
break
else:
print("PLEASE TYPE 'YES' OR 'NO'")
print("Please type \"YES\" or \"NO\"")
if answer == "NO":
break
print("THANKS FOR THE RACE")
print("Thanks for the race")
if medals["gold"] > 0:
print(f"GOLD MEDALS: {medals['gold']}")
print(f"Gold medals: {medals['gold']}")
if medals["silver"] > 0:
print(f"SILVER MEDALS: {medals['silver']}")
print(f"Silver medals: {medals['silver']}")
if medals["bronze"] > 0:
print(f"BRONZE MEDALS: {medals['bronze']}")
print(f"Bronze medals: {medals['bronze']}")