mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-22 07:10:42 -08:00
Python: Fix string concatenation
This commit is contained in:
@@ -68,9 +68,7 @@ def get_valid_guess():
|
||||
if len(set(guess)) == 3:
|
||||
valid = True
|
||||
else:
|
||||
print(
|
||||
"Oh, I forgot to tell you that " + "the number I have in mind"
|
||||
)
|
||||
print("Oh, I forgot to tell you that the number I have in mind")
|
||||
print("has no two digits the same.")
|
||||
else:
|
||||
print("What?")
|
||||
@@ -147,7 +145,7 @@ while still_running:
|
||||
guesses += 1
|
||||
if guesses > MAX_GUESSES:
|
||||
print("Oh well")
|
||||
print(f"That's {MAX_GUESSES} guesses. " + "My number was " + num_str)
|
||||
print(f"That's {MAX_GUESSES} guesses. My number was {num_str}")
|
||||
guessing = False
|
||||
|
||||
valid_response = False
|
||||
|
||||
@@ -23,8 +23,9 @@ class Basketball:
|
||||
print("Υou will be Dartmouth captain and playmaker.")
|
||||
print("Call shots as follows:")
|
||||
print(
|
||||
"1. Long (30ft.) Jump Shot; 2. Short (15 ft.) Jump Shot; "
|
||||
+ "3. Lay up; 4. Set Shot"
|
||||
"1. Long (30ft.) Jump Shot; "
|
||||
"2. Short (15 ft.) Jump Shot; "
|
||||
"3. Lay up; 4. Set Shot"
|
||||
)
|
||||
print("Both teams will use the same defense. Call Defense as follows:")
|
||||
print("6. Press; 6.5 Man-to-Man; 7. Zone; 7.5 None.")
|
||||
|
||||
@@ -104,7 +104,7 @@ def init_enemy():
|
||||
|
||||
# Messages correspond to outposts remaining (3, 2, 1, 0)
|
||||
PLAYER_PROGRESS_MESSAGES = (
|
||||
"YOU GOT ME, I'M GOING FAST. BUT I'LL GET YOU WHEN\n" "MY TRANSISTO&S RECUP%RA*E!",
|
||||
"YOU GOT ME, I'M GOING FAST. BUT I'LL GET YOU WHEN\nMY TRANSISTO&S RECUP%RA*E!",
|
||||
"THREE DOWN, ONE TO GO.\n\n",
|
||||
"TWO DOWN, TWO TO GO.\n\n",
|
||||
"ONE DOWN, THREE TO GO.\n\n",
|
||||
@@ -112,7 +112,7 @@ PLAYER_PROGRESS_MESSAGES = (
|
||||
|
||||
|
||||
ENEMY_PROGRESS_MESSAGES = (
|
||||
"YOU'RE DEAD. YOUR LAST OUTPOST WAS AT {}. HA, HA, HA.\n" "BETTER LUCK NEXT TIME.",
|
||||
"YOU'RE DEAD. YOUR LAST OUTPOST WAS AT {}. HA, HA, HA.\nBETTER LUCK NEXT TIME.",
|
||||
"YOU HAVE ONLY ONE OUTPOST LEFT.\n\n",
|
||||
"YOU HAVE ONLY TWO OUTPOSTS LEFT.\n\n",
|
||||
"YOU HAVE ONLY THREE OUTPOSTS LEFT.\n\n",
|
||||
|
||||
@@ -19,16 +19,11 @@ def print_lightning_bolt():
|
||||
|
||||
def print_solution(n):
|
||||
|
||||
print(
|
||||
"\n{} plus 3 gives {}. This Divided by 5 equals {}".format(
|
||||
n, n + 3, (n + 3) / 5
|
||||
)
|
||||
)
|
||||
print(f"\n{n} plus 3 gives {n + 3}. This Divided by 5 equals {(n + 3) / 5}")
|
||||
print(f"This times 8 gives {((n + 3) / 5) * 8}. If we divide 5 and add 5.")
|
||||
print(
|
||||
"We get {}, which, minus 1 equals {}".format(
|
||||
(((n + 3) / 5) * 8) / 5 + 5, ((((n + 3) / 5) * 8) / 5 + 5) - 1
|
||||
)
|
||||
f"We get {(((n + 3) / 5) * 8) / 5 + 5}, "
|
||||
f"which, minus 1 equals {((((n + 3) / 5) * 8) / 5 + 5) - 1}"
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ def print_summary_report(running_correct: int):
|
||||
if running_correct > 10:
|
||||
print()
|
||||
print("I GUESSED MORE THAN 1/3 OF YOUR NUMBERS.")
|
||||
print("I WIN." + "\u0007")
|
||||
print("I WIN.\u0007")
|
||||
elif running_correct < 10:
|
||||
print("I GUESSED LESS THAN 1/3 OF YOUR NUMBERS.")
|
||||
print("YOU BEAT ME. CONGRATULATIONS *****")
|
||||
|
||||
@@ -14,7 +14,6 @@ Supports Python version 3.8 or later.
|
||||
from random import random
|
||||
from typing import Final, FrozenSet, Optional, Tuple
|
||||
|
||||
|
||||
########################################################################################
|
||||
# Optional configs
|
||||
########################################################################################
|
||||
@@ -178,8 +177,8 @@ def get_move(current_loc: Optional[Tuple[int, int]]) -> Tuple[int, int]:
|
||||
else:
|
||||
prompt = (
|
||||
"PLEASE READ THE DIRECTIONS AGAIN.\n"
|
||||
+ "YOU HAVE BEGUN ILLEGALLY.\n\n"
|
||||
+ "WHERE WOULD YOU LIKE TO START? "
|
||||
"YOU HAVE BEGUN ILLEGALLY.\n\n"
|
||||
"WHERE WOULD YOU LIKE TO START? "
|
||||
)
|
||||
else:
|
||||
if (
|
||||
|
||||
@@ -1,26 +1,24 @@
|
||||
######################################################################
|
||||
#
|
||||
# Stars
|
||||
#
|
||||
# From: BASIC Computer Games (1978)
|
||||
# Edited by David H. Ahl
|
||||
#
|
||||
# "In this game, the computer selects a random number from 1 to 100
|
||||
# (or any value you set [for MAX_NUM]). You try to guess the number
|
||||
# and the computer gives you clues to tell you how close you're
|
||||
# getting. One star (*) means you're far away from the number; seven
|
||||
# stars (*******) means you're really close. You get 7 guesses.
|
||||
#
|
||||
# "On the surface this game is very similar to GUESS; however, the
|
||||
# guessing strategy is quite different. See if you can come up with
|
||||
# one or more approaches to finding the mystery number.
|
||||
#
|
||||
# "Bob Albrecht of People's Computer Company created this game."
|
||||
#
|
||||
#
|
||||
# Python port by Jeff Jetton, 2019
|
||||
#
|
||||
######################################################################
|
||||
"""
|
||||
Stars
|
||||
|
||||
From: BASIC Computer Games (1978)
|
||||
Edited by David H. Ahl
|
||||
|
||||
"In this game, the computer selects a random number from 1 to 100
|
||||
(or any value you set [for MAX_NUM]). You try to guess the number
|
||||
and the computer gives you clues to tell you how close you're
|
||||
getting. One star (*) means you're far away from the number; seven
|
||||
stars (*******) means you're really close. You get 7 guesses.
|
||||
|
||||
"On the surface this game is very similar to GUESS; however, the
|
||||
guessing strategy is quite different. See if you can come up with
|
||||
one or more approaches to finding the mystery number.
|
||||
|
||||
"Bob Albrecht of People's Computer Company created this game."
|
||||
|
||||
|
||||
Python port by Jeff Jetton, 2019
|
||||
"""
|
||||
|
||||
|
||||
import random
|
||||
@@ -31,7 +29,7 @@ MAX_GUESSES = 7
|
||||
|
||||
|
||||
def print_instructions():
|
||||
# "*** Instructions on how to play"
|
||||
"""Instructions on how to play"""
|
||||
print("I am thinking of a whole number from 1 to %d" % MAX_NUM)
|
||||
print("Try to guess my number. After you guess, I")
|
||||
print("will type one or more stars (*). The more")
|
||||
@@ -88,8 +86,8 @@ while still_playing:
|
||||
if guess == secret_number:
|
||||
# "*** We have a winner"
|
||||
player_has_won = True
|
||||
print("*************************" + "*************************!!!")
|
||||
print("You got it in %d guesses!!!" % guess_number)
|
||||
print("**************************************************!!!")
|
||||
print(f"You got it in {guess_number} guesses!!!")
|
||||
|
||||
else:
|
||||
print_stars(secret_number, guess)
|
||||
@@ -98,9 +96,7 @@ while still_playing:
|
||||
|
||||
# "*** Did not guess in [MAX_GUESS] guesses"
|
||||
if not player_has_won:
|
||||
print(
|
||||
"\nSorry, that's %d guesses, number was %d" % (guess_number, secret_number)
|
||||
)
|
||||
print(f"\nSorry, that's {guess_number} guesses, number was {secret_number}")
|
||||
|
||||
# Keep playing?
|
||||
response = input("\nPlay again? ")
|
||||
|
||||
@@ -117,9 +117,7 @@ def navigation():
|
||||
if warp == 0:
|
||||
return
|
||||
if warp < 0 or warp > 8:
|
||||
print(
|
||||
" CHIEF ENGINEER SCOTT REPORTS 'THE ENGINES WON'T TAKE " f"WARP {warp}!'"
|
||||
)
|
||||
print(f" CHIEF ENGINEER SCOTT REPORTS 'THE ENGINES WON'T TAKE WARP {warp}!'")
|
||||
return
|
||||
|
||||
n = round(warp * 8)
|
||||
@@ -160,9 +158,7 @@ def navigation():
|
||||
print(f"DAMAGE CONTROL REPORT: {devices[r1]} DAMAGED\n")
|
||||
else:
|
||||
d[r1] += random.random() * 3 + 1
|
||||
print(
|
||||
f"DAMAGE CONTROL REPORT: {devices[r1]} STATE OF " "REPAIR IMPROVED\n"
|
||||
)
|
||||
print(f"DAMAGE CONTROL REPORT: {devices[r1]} STATE OF REPAIR IMPROVED\n")
|
||||
|
||||
# begin moving starship
|
||||
insert_marker(int(s1), int(s2), " ")
|
||||
@@ -204,7 +200,7 @@ def navigation():
|
||||
q2 = s2 = 7
|
||||
if hit_edge:
|
||||
print("LT. UHURA REPORTS MESSAGE FROM STARFLEET COMMAND:")
|
||||
print(" 'PERMISSION TO ATTEMPT CROSSING OF GALACTIC " "PERIMETER")
|
||||
print(" 'PERMISSION TO ATTEMPT CROSSING OF GALACTIC PERIMETER")
|
||||
print(" IS HEREBY *DENIED*. SHUT DOWN YOUR ENGINES.'")
|
||||
print("CHIEF ENGINEER SCOTT REPORTS 'WARP ENGINES SHUT DOWN")
|
||||
print(
|
||||
@@ -392,14 +388,10 @@ def phaser_control():
|
||||
|
||||
h = int((h1 / fnd(i)) * (random.random() + 2))
|
||||
if h <= 0.15 * k[i][2]:
|
||||
print(
|
||||
"SENSORS SHOW NO DAMAGE TO ENEMY AT " f"{k[i][0] + 1} , {k[i][1] + 1}"
|
||||
)
|
||||
print(f"SENSORS SHOW NO DAMAGE TO ENEMY AT {k[i][0] + 1} , {k[i][1] + 1}")
|
||||
else:
|
||||
k[i][2] -= h
|
||||
print(
|
||||
f" {h} UNIT HIT ON KLINGON AT SECTOR " f"{k[i][0] + 1} , {k[i][1] + 1}"
|
||||
)
|
||||
print(f" {h} UNIT HIT ON KLINGON AT SECTOR {k[i][0] + 1} , {k[i][1] + 1}")
|
||||
if k[i][2] <= 0:
|
||||
print("*** KLINGON DESTROYED ***")
|
||||
k3 -= 1
|
||||
@@ -515,9 +507,7 @@ def klingons_fire():
|
||||
h = int((k[i][2] / fnd(i)) * (random.random() + 2))
|
||||
s -= h
|
||||
k[i][2] /= random.random() + 3
|
||||
print(
|
||||
f" {h} UNIT HIT ON ENTERPRISE FROM SECTOR " f"{k[i][0] + 1} , {k[i][1] + 1}"
|
||||
)
|
||||
print(f" {h} UNIT HIT ON ENTERPRISE FROM SECTOR {k[i][0] + 1} , {k[i][1] + 1}")
|
||||
if s <= 0:
|
||||
end_game(won=False, quit=False, enterprise_killed=True)
|
||||
return
|
||||
@@ -525,7 +515,7 @@ def klingons_fire():
|
||||
if h >= 20 and random.random() < 0.60 and h / s > 0.02:
|
||||
r1 = fnr()
|
||||
d[r1] -= h / s + 0.5 * random.random()
|
||||
print(f"DAMAGE CONTROL REPORTS '{devices[r1]} DAMAGED " "BY THE HIT'")
|
||||
print(f"DAMAGE CONTROL REPORTS '{devices[r1]} DAMAGED BY THE HIT'")
|
||||
|
||||
|
||||
def shield_control():
|
||||
@@ -585,7 +575,7 @@ def damage_control():
|
||||
if d3 >= 1:
|
||||
d3 = 0.9
|
||||
print("\nTECHNICIANS STANDING BY TO EFFECT REPAIRS TO YOUR SHIP;")
|
||||
print("ESTIMATED TIME TO REPAIR: " f"{round(0.01 * int(100 * d3), 2)} STARDATES")
|
||||
print(f"ESTIMATED TIME TO REPAIR: {round(0.01 * int(100 * d3), 2)} STARDATES")
|
||||
if input("WILL YOU AUTHORIZE THE REPAIR ORDER (Y/N)? ").upper().strip() != "Y":
|
||||
return
|
||||
|
||||
@@ -676,9 +666,7 @@ def computer():
|
||||
)
|
||||
return
|
||||
|
||||
print(
|
||||
"FROM ENTERPRISE TO KLINGON BATTLE " f"CRUISER{'S' if k3 > 1 else ''}"
|
||||
)
|
||||
print(f"FROM ENTERPRISE TO KLINGON BATTLE CRUISER{'S' if k3 > 1 else ''}")
|
||||
|
||||
for i in range(3):
|
||||
if k[i][2] > 0:
|
||||
@@ -697,7 +685,7 @@ def computer():
|
||||
return
|
||||
elif com == 4:
|
||||
print("DIRECTION/DISTANCE CALCULATOR:")
|
||||
print(f"YOU ARE AT QUADRANT {q1+1} , {q2+1} SECTOR " f"{s1+1} , {s2+1}")
|
||||
print(f"YOU ARE AT QUADRANT {q1+1} , {q2+1} SECTOR {s1+1} , {s2+1}")
|
||||
print("PLEASE ENTER")
|
||||
while True:
|
||||
coordinates = input(" INITIAL COORDINATES (X,Y)? ").split(",")
|
||||
@@ -908,7 +896,7 @@ def end_game(won=False, quit=True, enterprise_killed=False):
|
||||
if won:
|
||||
print("CONGRATULATIONS, CAPTAIN! THE LAST KLINGON BATTLE CRUISER")
|
||||
print("MENACING THE FEDERATION HAS BEEN DESTROYED.\n")
|
||||
print("YOUR EFFICIENCY RATING IS " f"{round(1000 * (k7 / (t - t0))**2, 4)}\n\n")
|
||||
print(f"YOUR EFFICIENCY RATING IS {round(1000 * (k7 / (t - t0))**2, 4)}\n\n")
|
||||
else:
|
||||
if not quit:
|
||||
if enterprise_killed:
|
||||
@@ -926,7 +914,7 @@ def end_game(won=False, quit=True, enterprise_killed=False):
|
||||
|
||||
print("THE FEDERATION IS IN NEED OF A NEW STARSHIP COMMANDER")
|
||||
print("FOR A SIMILAR MISSION -- IF THERE IS A VOLUNTEER,")
|
||||
if input("LET HIM STEP FORWARD AND " "ENTER 'AYE'? ").upper().strip() != "AYE":
|
||||
if input("LET HIM STEP FORWARD AND ENTER 'AYE'? ").upper().strip() != "AYE":
|
||||
exit()
|
||||
restart = True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user