generated from Code-Institute-Org/python-essentials-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun.py
More file actions
163 lines (132 loc) · 4.31 KB
/
run.py
File metadata and controls
163 lines (132 loc) · 4.31 KB
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
155
156
157
158
159
160
161
162
163
import random
import time
red = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35]
black = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36]
green = [0]
player_choice = ""
bank = 500
numbers_combined = 36
stake = 0
def start_game_func():
"""
funtion that welcomes the player into the game
"""
print("Welcome to the python roulette game!\n")
print("You play the game by chosing a color you want to play\n")
print(f'Red: {red}\nBlack: {black}\nGreen: {green}\n')
print("After you have picked a color to play on you can place your bet\n")
print("The odds for all the colors are:\nRed = 2x the money\nBlack = 2x the money\nGreen = 35x the money\n")
def choice_of_color():
"""
function that makes an input for the user to chose their color they want to bet on.
"""
global player_choice
global red
global black
global green
input_color = input("Choose your color:\n").lower()
if input_color == "red":
player_choice = red
print("Red is your choice\n")
print(f'Your numbers is: {player_choice}\n')
elif input_color == "black":
player_choice = black
print("Black is your choice\n")
print(f'Your numbers is: {player_choice}\n')
elif input_color == "green":
player_choice = green
print("Green is your choice\n")
print(f'Your numbers is: {player_choice}\n')
else:
print("pick beetween red, black and green\n")
choice_of_color()
return player_choice
def taking_stake():
"""
takes the bet that the player wants to play
"""
global bank
global stake
print(f'Your current balance is {bank}')
while True:
try:
stake = int(input("How much do you want to bet?:\n"))
if stake <= bank:
print(f'you played {stake} credits on {player_choice}\n')
else:
print("You can't bet more money then you own...\n")
taking_stake()
break
except ValueError:
print("You need to type an whole number\n")
return stake
def random_number_selector():
"""
function that returns and makes the choice of random number
"""
global numbers_combined
numbers_combined = random.randrange(0, 36)
print("The roulette is now starting\n")
time.sleep(2)
print("The ball is losing speed...\n")
time.sleep(2)
if numbers_combined in player_choice:
print("You won!\n")
else:
print("sorry you lost...\n")
print(f'The winning number is {numbers_combined}\n')
return numbers_combined
def the_bank():
"""
function that calculate the stakes and what the player wins/loses. returns the current bank balance
"""
global bank
global stake
global numbers_combined
if numbers_combined in player_choice:
if player_choice == red:
stake = stake * 2 - stake
bank = stake + bank
print(f'You won {stake} credits! current bank balance is now {bank}\n')
elif player_choice == black:
stake = stake * 2 - stake
bank = stake + bank
print(f'You won {stake} credits! current bank balance is now {bank}\n')
elif player_choice == green:
stake = stake * 35 - stake
bank = stake + bank
print(f'You won {stake} credits! current bank balance is now {bank}\n')
else:
bank = bank - stake
print(f'You lost {stake} and your current bank balance is {bank}\n')
return bank
def bank_empty():
"""
function that notice if the bank is = 0 and if True closes the game so the user will have to start over
"""
global bank
if bank == 0:
print("Sorry you are out of credit...")
time.sleep(2)
exit()
def exit_function():
"""
Function that gives the user an option to close the game after each time playing
"""
exit_input = input("Type: 'y' if you want to continue, else type: 'n':\n")
if exit_input.lower() == "n":
exit()
else:
main()
def main():
"""
containing all the functions except the start game function
"""
choice_of_color()
taking_stake()
random_number_selector()
the_bank()
bank_empty()
exit_function()
start_game_func()
main()