Last active
July 19, 2022 22:46
-
-
Save daniel-schroeder-dev/0b69d5b1b4a03f84ae0ae0f3e28a5f72 to your computer and use it in GitHub Desktop.
Roman Slots
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
################ HINTS ##################################### | |
Create an app that models a slot machine. | |
- Our user needs tokens to play the slot machine, so create a variable to hold | |
these tokens and store as many as you wish at the start of the app. | |
- Track the number of rounds the user plays in a variable as well. | |
- Create a loop that runs while the user has tokens. | |
In the loop: | |
- Display the number of tokens left | |
- Check to see if the user wants to keep playing | |
- If they don't, break out of the loop immediately | |
- Take away a token during each loop | |
- Get three random numbers between 1 and a value of your choosing. These | |
represent the slots of your slot machine. | |
- The larger the range, the harder it is to win | |
- Display these three numbers (slots) in a manner of your choosing. | |
- Ex: | 2 | 1 | 2 | | |
- Ex: ## 3 ## 4 ## 1 ## | |
- Check the slots to see if: | |
- All three slots are equivalent | |
- Print a message telling the user they've doubled their tokens | |
and double the tokens the user has | |
- A pair of adjacent slots are equivalent | |
- Print a message telling the user they've got a pair and get two | |
more tokens. Also, increase the tokens by two. | |
- For any other situation, display a message saying something like: | |
"No matches..." | |
- At the end of the loop, increase the number of rounds played | |
After the loop exits, print the number of rounds played and the number of | |
tokens the user has left. | |
Example output: | |
------------------------------------------------------------------------------- | |
You have 5 tokens. | |
Spend 1 token to play? (y/n) y | |
1 | 4 | 1 | |
No matches... | |
You have 4 tokens. | |
Spend 1 token to play? (y/n) y | |
3 | 3 | 1 | |
Pair, not bad. You earned 2 tokens! | |
You have 5 tokens. | |
Spend 1 token to play? (y/n) y | |
4 | 2 | 4 | |
No matches... | |
You have 4 tokens. | |
Spend 1 token to play? (y/n) y | |
3 | 2 | 3 | |
No matches... | |
You have 3 tokens. | |
Spend 1 token to play? (y/n) y | |
4 | 4 | 4 | |
3 in a row! You doubled your tokens! | |
You have 4 tokens. | |
Spend 1 token to play? (y/n) n | |
You played 5 rounds and finished with 4 tokens. | |
------------------------------------------------------------------------------- | |
############################################################ | |
""" | |
from random import randint | |
user_tokens = 4 | |
max_num = 4 | |
print("You have 4 tokens.") | |
while max_num >= 0: | |
print("Spend one token to play?") | |
user_choice = int(input("Choose (1) Yes or (2) No: ")) | |
if user_choice == 2: | |
break | |
slot_num = randint(1,max_num) | |
slot_numb = randint(1,max_num) | |
slot_numbe = randint(1,max_num) | |
user_tokens -= 1 | |
print(f"## {slot_num} ## {slot_numb} ## {slot_numbe} ##") | |
if slot_num == slot_numb == slot_numbe: | |
user_tokens *= 2 | |
print(f"Tokens that remain: {user_tokens}") | |
elif slot_num == slot_numb or ___ == ___: | |
user_tokens += 2 | |
print(f"Tokens that remain: {user_tokens}") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment