Giter Site home page Giter Site logo

python-slot-machine's Introduction

Python-Slot-Machine

python-slot-machine's People

Contributors

techwithtim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-slot-machine's Issues

run out of funds run out of fun or nah

when the balance is null after spinning we need to deposit more.

soo in the spin function i believe this is needed

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

we have to tell the user when we have to run out off funds

import random

MAX_LINES = 3
MAX_BET = 100
MIN_BET = 1

ROWS = 3
COLS = 3

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

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

def check_winnings(columns, lines, bet, values):
winnings = 0
winning_lines = []
for line in range(lines):
symbol = columns[0][line]
for column in columns:
symbol_to_check = column[line]
if symbol != symbol_to_check:
break
else:
winnings += values[symbol] * bet
winning_lines.append(line + 1)

return winnings, winning_lines

def get_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[:]
    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()

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

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():
lines = int(lines)
if 1 <= lines <= MAX_LINES:
break
else:
print("Enter a valid number of lines.")
else:
print("Please enter a number.")

return lines

def get_bet():
while True:
amount = input("What 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}.")
else:
print("Please enter a number.")

return amount

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

    if balance < 3:
        break

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

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)
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:
if balance < 3:
print("""U lost a lot of money fool now quit the game
r u have deposit again
to lose all money again
hava a luck man:: """)
print(f"Current balance is ${balance}")
answer = input("Press enter to play (q to quit).")
if answer == "q":
break
balance += spin(balance)

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

main()

Python index list out of range on 3.10 V studio and python 3.10 for row in range enumerate

i followed the youtube video exactly and i even copy pasted the full code stack on git to my VS IDE
it still doesnt work

Message=list index out of range
Source=C:\Users\leron\source\repos\Lottery App\Lottery_App.py
StackTrace:
File "C:\Users\leron\source\repos\Lottery App\Lottery_App.py", line 38, in print_slot_machine
for row in range(len(columns[0])):
File "C:\Users\leron\source\repos\Lottery App\Lottery_App.py", line 110, in main
print_slot_machine(slots)
File "C:\Users\leron\source\repos\Lottery App\Lottery_App.py", line 116, in (Current frame)
main()

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()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.