Skip to content

Commit

Permalink
Merge pull request #2298 from avinashkranjan/deepsource-transform-886…
Browse files Browse the repository at this point in the history
…61162

format code with autopep8
  • Loading branch information
avinashkranjan authored Jul 21, 2023
2 parents a9a88e7 + e5c6951 commit 225b071
Showing 1 changed file with 33 additions and 21 deletions.
54 changes: 33 additions & 21 deletions Slot-Machine-Game/slotmachine.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import random
import random
MAX_LINES = 3
MAX_BET = 100
MIN_BET = 1
Expand All @@ -20,6 +20,7 @@
"D": 2
}


def check_winnings(columns, lines, bet, values):
winnings = 0
winning_lines = []
Expand All @@ -28,14 +29,15 @@ def check_winnings(columns, lines, bet, values):
for column in columns:
symbol_to_check = column[line]
if symbol != symbol_to_check:
break
break
else:
winnings +=values[symbol]* bet
winnings += values[symbol] * bet
winning_lines.append(line + 1)

return winnings, winning_lines

def get_slot_machine_spin(rows,cols, symbols):

def get_slot_machine_spin(rows, cols, symbols):
all_symbols = []
for symbol, symbol_count in symbols.items():
for _ in range(symbol_count):
Expand All @@ -54,16 +56,18 @@ def get_slot_machine_spin(rows,cols, symbols):

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=" | ")
if i != len(columns)-1:
print(column[row], end=" | ")
else:
print(column[row], end="")

print()


def deposit():
while True:
amount = input("What would you like to deposit? $")
Expand All @@ -78,19 +82,22 @@ def deposit():

return amount


def get_number_of_lines():
while True:
lines = input("Enter the number of lines to bet on (1-" + str(MAX_LINES) + ")? ")
if lines.isdigit():
while True:
lines = input(
"Enter the number of lines to bet on (1-" + str(MAX_LINES) + ")? ")
if lines.isdigit():
lines = int(lines)
if 1<= lines <= MAX_LINES:
if 1 <= lines <= MAX_LINES:
break
else:
print("enter a valid number of lines.")
else:
else:
print("please enter a number. ")

return lines
return lines


def get_bet():
while True:
Expand All @@ -105,28 +112,32 @@ def get_bet():
print("please enter a number. ")

return amount



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

if total_bet > balance:
print(f"You do not have enough money to bet that amount, your current balance is: ${balance}.")
if total_bet > balance:
print(
f"You do not have enough money to bet that amount, your current balance is: ${balance}.")

else:
break
else:
break

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

slots = get_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:
Expand All @@ -138,4 +149,5 @@ def main():

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


main()

0 comments on commit 225b071

Please sign in to comment.