Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 37 additions & 47 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
import random

MAX_LINES = 3
MAX_BET = 100
MAX_BET = 1000
MIN_BET = 1

ROWS = 3
COLS = 3

symbol_count = {
"A": 2,
"B": 4,
"C": 6,
"A": 3,
"B": 6,
"C": 4,
"D": 8
}

symbol_value = {
"A": 5,
"B": 4,
"C": 3,
"A": 6,
"B": 3,
"C": 4,
"D": 2
}


def check_winnings(columns, lines, bet, values):
winnings = 0
winning_lines = []
Expand All @@ -34,120 +33,111 @@ def check_winnings(columns, lines, bet, values):
else:
winnings += values[symbol] * bet
winning_lines.append(line + 1)
return winnings , winning_lines

return winnings, winning_lines


def get_slot_machine_spin(rows, cols, symbols):
def slot_machine_spin(rows, cols, symbols):
all_symbols = []
for symbol, symbol_count in symbols.items():
for _ in range(symbol_count):
all_symbols.append(symbol)

columns = []
for _ in range(cols):
column = []
current_symbols = all_symbols[:]
current_symbols = all_symbols[:] #copy of list : to copy a list use [:]
for _ in range(rows):
value = random.choice(current_symbols)
current_symbols.remove(value)
column.append(value)

columns.append(column)

return columns


def print_slot_machine(columns):
for row in range(len(columns[0])):
for i, column in enumerate(columns):
if i != len(columns) - 1:
print(column[row], end=" | ")
else:
print(column[row], end="")

print()


# input how much you want to deposit function
def deposit():
while True:
amount = input("What would you like to deposit? $")
amount = input("How much would you like to deposit? $")
if amount.isdigit():
amount = int(amount)
if amount > 0:
break
else:
print("Amount must be greater than 0.")
print("Amount must be greater than $0")
else:
print("Please enter a number.")
print("Please enter a valid Number!")

return amount


def get_number_of_lines():
# function for picking num of lines to bet on
def get_num_of_lines():
while True:
lines = input(
"Enter the number of lines to bet on (1-" + str(MAX_LINES) + ")? ")
lines = input("enter a number of lines to bet on (1 - {})? ".format(MAX_LINES))
if lines.isdigit():
lines = int(lines)
if 1 <= lines <= MAX_LINES:
break
else:
print("Enter a valid number of lines.")
print("Enter a Valid Number of lines")
else:
print("Please enter a number.")
print("Please enter a valid Number!")

return lines


#function for picking how much you would like to bet for each line
def get_bet():
while True:
amount = input("What would you like to bet on each line? $")
amount = input("How much would you like to bet on each line? $")
if amount.isdigit():
amount = int(amount)
if MIN_BET <= amount <= MAX_BET:
break
else:
print(f"Amount must be between ${MIN_BET} - ${MAX_BET}.")
print("Amount must be between ${} - ${}".format(MIN_BET, MAX_BET))
else:
print("Please enter a number.")
print("Please enter a valid Number!")

return amount


def spin(balance):
lines = get_number_of_lines()
lines = get_num_of_lines()
while True:
bet = get_bet()
total_bet = bet * lines

if total_bet > balance:
print(
f"You do not have enough to bet that amount, your current balance is: ${balance}")
print("you dont have enough money deposited to make this bet, current balance is ${}".format(balance))
else:
break
print("You are betting ${bet} on {lines} lines, Total is ${total_bet}".format(bet=bet, lines=lines, total_bet=total_bet))

print(
f"You are betting ${bet} on {lines} lines. Total bet is equal to: ${total_bet}")

slots = get_slot_machine_spin(ROWS, COLS, symbol_count)
slots = slot_machine_spin(ROWS, COLS, symbol_count)
print_slot_machine(slots)
winnings, winning_lines = check_winnings(slots, lines, bet, symbol_value)
print(f"You won ${winnings}.")
print(f"You won on lines:", *winning_lines)
return winnings - total_bet


def main():
balance = deposit()
while True:
print(f"Current balance is ${balance}")
answer = input("Press enter to play (q to quit).")
while balance > 0:
print(f"Current balance is: ${balance}")
answer = input("press enter to spin! (Press Q to quit)")
if answer == "q":
break
balance += spin(balance)

print(f"You left with ${balance}")

while balance == 0:
ans = input("You are out of money! press Y to deposit more, or press Q to quit: ")
if ans == "y":
main()
if ans == "q":
break


main()