peconia / slot_machine.py
This file contains 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
import random , time |
def reel (): |
return random . choice ( ‘7♣♣♠♠♠♦♦♦♥♥♥♥’ ) |
def print_row ( first , second , third ): |
print ( ‘[ <> | <> | <> ]’ . format ( first , second , third , t = time . sleep ( .15 )), end = ‘ \ ‘ ) |
def round (): |
for i in range ( 30 ): |
if i < 12 : |
first = reel () |
second = reel () |
third = reel () |
print_row ( first , second , third ) |
elif i < 25 : |
first = first |
second = reel () |
third = reel () |
print_row ( first , second , third ) |
else : |
first = first |
second = second |
third = reel () |
print_row ( first , second , third ) |
return ( first , second , third ) |
def ask_to_play (): |
global stake |
while ( True ): |
answer = input ( “You have £” + str ( stake ) + “. Would you like to play? y/n ” ) |
answer = answer . lower (). strip () |
if ( answer == “y” ): |
return True |
elif ( answer == “n” ): |
print ( “You ended the game with £” + str ( stake ) + ” in your hand.” ) |
return False |
else : |
print ( “incorrect input – type either y or n” ) |
def check_win ( a , b , c ): |
global stake |
if a == 7 and b == 7 and c == 7 : |
winnings = 250 |
elif a == 7 and b == 7 and ( c == “♣” or c == “♠” ): |
winnings = 100 |
elif a == “♣” and b == “♣” and ( c == 7 or c == “♣” ): |
winnings = 40 |
elif a == “♠” and b == “♠” and ( c == 7 or c == “♠” ): |
winnings = 20 |
elif a == “♦” and b == “♦” and c == “♦” : |
winnings = 15 |
elif a == “♦” and b == “♦” : |
winnings = 5 |
elif a == “♥” and b == “♥” and c == “♥” : |
winnings = 3 |
elif a == “♥” and b == “♥” : |
winnings = 2 |
else : |
winnings = 0 |
if winnings > 0 : |
stake += winnings |
print ( “Congratulations! You just won £” + str ( winnings ) + “. ” ) |
else : |
print ( “Sorry, no win this time.” ) |
def play (): |
global stake |
want_to_play = ask_to_play () |
while ( stake >= 1 and want_to_play == True ): |
stake -= 1 ; |
round1 = round () |
a , b , c = round1 |
print ( ‘[ <> | <> | <> ]’ . format ( a , b , c )) |
check_win ( a , b , c ) |
if stake == 0 : |
print ( “Sorry mate, you ran out of money!” ) |
break ; |
want_to_play = ask_to_play () |
print ( ”’Welcome to play the Slot Machine! |
You’ll start with £20. You can choose to quit |
and cash out after each round. Each round costs £1. |
To win you must get one of the following combinations: |
7 \t 7 \t 7 \t pays \t £250 |
7 \t 7 \t ♣ / ♠ \t pays \t £100 |
♣ \t ♣ \t ♣ / 7 \t pays \t £40 |
♠ \t ♠ \t ♠ / 7 \t pays \t £20 |
♦ \t ♦ \t ♦ \t pays \t £15 |
♦ \t ♦ \t – \t pays \t £5 |
♥ \t ♥ \t ♥ \t pays \t £3 |
♥ \t ♥ \t – \t pays \t £2 |
”’ ) |
stake = 20 |
play () |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Tag: cmd368体育官网-【copy url:hk589.net】-bob官方下载登陆-【copy url:hk589.net】-d11
Powered by wpForo version 2.1.5
Get in touch
P. O Box, 3138, Kampala
Plot 806, Block 213, Bukoto-Kisasi Road – Kampala
– info@seatiniuganda.org
– +256 414 540856
Thematic Areas
- Trade, Investment and Sustainable Development
- Financing for Development
- Building Alternatives for Social & Economic Justice
- Equator School of Development Policy
Quick Links
Connect with us
Join our mailing list
Copyright © 2024 SEATINI. All Rights Reserved
Daftar istilah pencarian CMD368 Member Function Login yang dicari: