mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-01-12 21:24:04 -08:00
add 00_Alternate_Langage folder and move alternate ports there
This commit is contained in:
3
00_Alternate_Languages/47_Hi-Lo/python/README.md
Normal file
3
00_Alternate_Languages/47_Hi-Lo/python/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Python](https://www.python.org/about/)
|
||||
53
00_Alternate_Languages/47_Hi-Lo/python/hilo.py
Normal file
53
00_Alternate_Languages/47_Hi-Lo/python/hilo.py
Normal file
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env python3
|
||||
import random
|
||||
|
||||
MAX_ATTEMPTS = 6
|
||||
QUESTION_PROMPT = "? "
|
||||
|
||||
|
||||
def play():
|
||||
print("HI LO")
|
||||
print("CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n\n\n")
|
||||
print("THIS IS THE GAME OF HI LO.\n")
|
||||
print("YOU WILL HAVE 6 TRIES TO GUESS THE AMOUNT OF MONEY IN THE")
|
||||
print("HI LO JACKPOT, WHICH IS BETWEEN 1 AND 100 DOLLARS. IF YOU")
|
||||
print("GUESS THE AMOUNT, YOU WIN ALL THE MONEY IN THE JACKPOT!")
|
||||
print("THEN YOU GET ANOTHER CHANCE TO WIN MORE MONEY. HOWEVER,")
|
||||
print("IF YOU DO NOT GUESS THE AMOUNT, THE GAME ENDS.\n\n")
|
||||
|
||||
total_winnings = 0
|
||||
while True:
|
||||
print()
|
||||
secret = random.randint(1, 100)
|
||||
guessed_correctly = False
|
||||
|
||||
for attempt in range(MAX_ATTEMPTS):
|
||||
print("YOUR GUESS", end=QUESTION_PROMPT)
|
||||
guess = int(input())
|
||||
|
||||
if guess == secret:
|
||||
print(f"GOT IT!!!!!!!!!! YOU WIN {secret} DOLLARS.")
|
||||
guessed_correctly = True
|
||||
break
|
||||
elif guess > secret:
|
||||
print("YOUR GUESS IS TOO HIGH.")
|
||||
else:
|
||||
print("YOUR GUESS IS TOO LOW.")
|
||||
|
||||
if guessed_correctly:
|
||||
total_winnings += secret
|
||||
print(f"YOUR TOTAL WINNINGS ARE NOW {total_winnings} DOLLARS.")
|
||||
else:
|
||||
print(f"YOU BLEW IT...TOO BAD...THE NUMBER WAS {secret}")
|
||||
|
||||
print("\n")
|
||||
print("PLAY AGAIN (YES OR NO)", end=QUESTION_PROMPT)
|
||||
answer = input().upper()
|
||||
if answer != "YES":
|
||||
break
|
||||
|
||||
print("\nSO LONG. HOPE YOU ENJOYED YOURSELF!!!")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
play()
|
||||
Reference in New Issue
Block a user