-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgames.py
154 lines (141 loc) · 5.57 KB
/
games.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import random
money = 100
def coin_flip(bet):
print('Playing coin flip!')
if bet > 0 and bet < money:
coin_flip_result = random.randint(0,1)
outcome = None
call = input('Pick a side!')
call = call.lower().title()
if call == 'Heads' or call == 'Tails':
if coin_flip_result == 0:
outcome = 'Heads'
print(outcome)
else:
outcome = 'Tails'
print(outcome)
if outcome == call:
print(f'You won! You earn {bet} dollars!')
return bet
else:
print(f'You lost! You lose {bet} dollars!')
return bet * -1
else:
print('Enter heads or tails!')
else:
print('Enter a postive number/enter within the range of your money!')
def cho_han(bet):
print('Playing cho_han!')
if bet > 0 and bet < money:
dice1 = random.randint(1,6)
dice2 = random.randint(1,6)
total = (dice1 + dice2) % 2
call = input('Choose even or odd!')
call = call.lower().title()
if call == 'Even' or call == 'Odd':
if total == 0:
outcome = 'Even'
print(outcome)
else:
outcome = 'Odd'
print(outcome)
if outcome == call:
print(f'You won! You earn {bet} dollars!')
return bet
else:
print(f'You lost! You lose {bet} dollars!')
return bet * -1
else:
print('Enter even or odd!')
else:
print('Enter a postive number/enter within the range of your money!')
def pick_a_card(bet):
print('Playing pick a card!')
if bet > 0 and bet < money:
card_deck = ['Ace', 2, 3, 4, 5, 6, 7, 8, 9, 10, 'Jack', 'Queen', 'King']
player_call = random.randint(0, len(card_deck)-1)
computer_call = random.randint(0, len(card_deck)-1)
player_choice = card_deck[player_call]
print(f'You picked the card: {player_choice}')
computer_choice = card_deck[computer_call]
print(f'Player2 picked the card: {computer_choice}')
if player_choice == 'Ace':
player_choice = 1
elif player_choice == 'Jack' or player_choice == 'Queen' or player_choice == 'King':
player_choice = 10
if computer_choice == 'Ace':
computer_choice = 1
elif computer_choice == 'Jack' or computer_choice == 'Queen' or computer_choice == 'King':
computer_choice = 10
if player_choice > computer_choice:
print(f'You won! You earn {bet} dollars.')
return bet
elif computer_choice > player_choice:
print(f'You lost! You lose {bet} dollars.')
return bet * -1
elif player_choice == computer_choice:
print('A tie! You neither lose nor earn anything.')
return 0
else:
print('Enter a postive number/enter within the range of your money!')
def roulette(bet):
print('Playing roulette!')
if bet > 0 and bet < money:
what_bet = input('What would you like to bet on? Choose: color, parity, or number.')
what_bet = what_bet.lower()
call = None
if what_bet == 'color':
call = input('Pick red or black!')
call = call.lower().title()
if what_bet == 'number':
call = input('Pick a number from 1 to 37.')
if what_bet == 'parity':
call = input('Pick odd or even!')
call = call.lower().title()
even_or_odd = lambda num: 'Even' if num%2==0 else 'Odd'
red_or_black = lambda num: 'Red' if num in red_numbers else 'Black'
nums = range(1, 37)
red_numbers = [1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36]
spin_dict = {}
for num in nums:
spin_dict[num] = even_or_odd(num), red_or_black(num)
key = random.choice(list(spin_dict.keys()))
b, c = spin_dict.get(key)
spin = f'{key} {b, c}'
print(spin)
if type(call) != int:
if call in spin:
print(f'You won! You earn {bet} dollars.')
return bet
else:
print(f'You lost! You lose {bet} dollars.')
return bet * -1
else:
if call in spin:
print(f'You won! You earn {bet * 35} dollars.')
return bet * 35
else:
print(f'You lost! You lose {bet} dollars.')
return bet * -1
else:
print('Enter a positive number/enter within the range of your money!')
def play_game():
pick_a_game = input('What game would you like to play: coin flip, pick a card, cho han, or roulette?')
pick_a_game = pick_a_game.lower()
if pick_a_game == 'coin flip':
bet = int(input('Bet money!'))
money += coin_flip(bet)
print(f'Your current money is {money}')
if pick_a_game == 'cho han':
bet = int(input('Bet money!'))
money += cho_han(bet)
print(f'Your current money is {money}')
if pick_a_game == 'pick a card':
bet = int(input('Bet money!'))
money += pick_a_card(bet)
print(f'Your current money is {money}')
if pick_a_game == 'roulette':
bet = int(input('Bet money!'))
money += roulette(bet)
print(f'Your current money is {money}')
play_game()