mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-21 23:00:43 -08:00
Python: Fix string concatenation
This commit is contained in:
@@ -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? ")
|
||||
|
||||
Reference in New Issue
Block a user