How do I make the balance work correctly? It is calculating wrong and not keeping the…
- User
How do I make the balance work correctly? It is calculating wrong and not keeping the value throughout the code. import random
Define variables
balance = 100 earnings = 0 cost = 1 response = ""
List of fruits
fruits = ['lemon','cherry','bar']
Play the game
while balance > 0 and response != "n":
balance = 100 earnings = 0 cost = 1 response = "" # pick one random fruit for each dial dial1=random.choice(fruits) dial2=random.choice(fruits) dial3=random.choice(fruits) print(dial1) print(dial2) print(dial3) # check if all the fruits are the same if dial1 == dial2 == dial3: if dial1 == 'bar': earnings+=100 print('\n!!Jackpot!!','balance:',balance+earnings) # Here, I've removed -cost because the cost is already subtracted in the line above elif dial1=='lemon': earnings+=25 print('\nMatch three ' + dial1 + 's and win 25!','\nbalance:', balance+earnings) elif dial1=='cherry': earnings+=50 print('\nMatch three ' + dial1 + 's and win 50!' ,balance+earnings) else: print('\n balance',balance) # Ask the player if they want to play again response = raw_input("spin again? (y/n): ")
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.