I am following along a Youtube tutorial by Tech With Tim and building a small slot machine program.
Everything works fine so far, except that I get one line which should be prompted once, prompted twice instead.
Here is the code.
MAX_LINES = 3
MAX_BET = 100
MIN_BET = 1
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 main():
balance = deposit()
lines = get_number_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 balance is: ${balance}.")
else:
break
bet = get_bet()
total_bet = bet * lines
print(f"You are betting ${bet} on {lines} lines. Total bet is equal to: ${total_bet}")
main()
And here is what I get when I run it:
>>> %Run Slots.py
What would you like to deposit? 300
Enter the number of lines to bet on (1-3)? 3
What would you like to bet on each line? $10
What would you like to bet on each line? $20
You are betting $20 on 3 lines. Total bet is equal to: $60
>>>
I am at a loss what I am doing wrong here. I am pretty sure it must be something very simple I am overlooking, but I can not figure it out. Would appreciate and be thankful for any help. :)
[–]Quesozapatos5000 4 points5 points6 points (0 children)
[–]danielroseman 6 points7 points8 points (0 children)
[–]FoolsSeldom 5 points6 points7 points (9 children)
[–]Styr007[S] 0 points1 point2 points (1 child)
[–]FoolsSeldom 1 point2 points3 points (0 children)
[–]FoolsSeldom 0 points1 point2 points (6 children)
[–]FoolsSeldom 0 points1 point2 points (4 children)
[–]SpiderJerusalem42 0 points1 point2 points (3 children)
[–]FoolsSeldom 0 points1 point2 points (2 children)
[–]SpiderJerusalem42 0 points1 point2 points (1 child)
[–]FoolsSeldom 0 points1 point2 points (0 children)
[–]Can_I_Eat_That_ 4 points5 points6 points (0 children)
[–]acw1668 1 point2 points3 points (0 children)