This repository was archived by the owner on Oct 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCoinFlip.py
More file actions
68 lines (58 loc) · 1.73 KB
/
Copy pathCoinFlip.py
File metadata and controls
68 lines (58 loc) · 1.73 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
import os
import random
from SaveHandling import *
def CoinFlip(coins):
user_returned = False
while True:
#Sides and random pick
sides = ['heads','h','tails','t']
rand_int = random.randint(0, 1)
adjust_coins(coins)
print(f"To go back just type 'return'\n")
print(f'Coin Amount: ', coins)
print('Options: Heads(H) & Tails(T)')
#Get user input, check if 'return'
user_input: str = input('Pick side: ')
if user_input.lower() == 'return':
user_returned = True
break
while True:
try:
bet = int(input('Bet Amount: '))
break
except ValueError:
print("Please enter a valid integer.")
#Make sure user pick is a valid color
if user_input.lower() in sides and BetCheck(bet, coins):
print('Side Flipped:', sides[rand_int])
#Win/Lose condition
if sides[rand_int] == user_input.lower():
coins += bet
Clear()
print(f'You won {bet} coins!')
continue
else:
coins -= bet
Clear()
print(f'You lost {bet} coins.')
continue
#If not valid, restart
else:
Clear()
print('Not Valid')
continue
if user_returned:
return coins
def BetCheck(bet: int, coins: int):
"""
Check user bet to make sure its valid
"""
if bet <= coins and bet != 0:
return bet
else:
return None
def Clear():
"""
Clear Terminal
"""
os.system('cls')