Python Forum
Fruit Machine - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Fruit Machine (/thread-5709.html)



Fruit Machine - TDiamondBro - Oct-17-2017

I need to make a fruit machine in Python. The fruits/items spinning are Cherry, Lemon, Bell, Star and Skull. The Success criteria is •

• If two symbols are rolled the user wins 50p.

• If two skulls are rolled user loses £1, if three skulls are rolled loses all money.

• If you get 3 of the same you get £1, if 3 bells rolled £5.

• Starts with £1, each go costs 20p.



Every time I run the code and I get two of the same items it doesn't add 50p to the credit or add £1 and the credit doesn't properly show for example ... if 1 go costs 20p and I start off with £1 that's 80p. But when I win 50p the new credit should be £1.30 which is not the case. I need help fixing and improving my code.



print("##############################")
print("#                            #")
print("#      | Fruit Machine |     #")
print("#       | By Sam Jiji |      #")
print("#                            #")
print("##############################")
print("")

while True:

    import random

    credit = 1

    wheel = ['Cherry', 'Lemon', 'Bell', 'Star', 'Skull']

    reel1 = random.choice(wheel)
    reel2 = random.choice(wheel)
    reel3 = random.choice(wheel)

    start = input("Enter Roll or Quit? ")
    
    if start == "quit" or start == "Quit":
      print("Your winnings are £" + str(credit))
      break
    
    if start == "roll" or start == "Roll":
      credit = (credit - 0.20)
      print("-20p")
      print("Credit now £" + str(credit))
      print()
      print("\n ***  Spinning Wheels... *** \n")
      print()
      print(reel1 + " - " + reel2 + " - " + reel3 + "\n")
      print()
      
      if start != "quit" or start != "roll":
        continue

      credit = (round(credit, 2))
      
      if credit < 0:
        print(" Sorry Unable to play no credits")
        break
      
      if reel1 == "Skull" and reel2 =="Skull" and reel3 == "Skull":
        print(" You lost all your money! :-(")
        credit = (credit - credit)

      if reel1 == "Skull" == reel2 =="Skull" or reel2 == "Skull" == reel3 =="Skull" or reel1 == "Skull" == reel3 =="Skull":
        print(" You lost £1!\n")
        credit = (credit - 1)

      if reel1 == reel2 or reel2 == reel3 or reel1 == reel3: 
        print(" $-$ 50p Won $-$\n")
        credit = (credit + 0.5)
  
      if reel1 == reel2 == reel3:
        print(" $$$ £1 Won $$$\n")
        credit = (credit + 1)
  
      if reel1 == "Bell" == reel2 == "Bell" == reel3 == "Bell":
        print(" $$$ £5 won $$$ ")
        credit = (credit + 5)

      credit = (round(credit, 2))

      print("Credit now £" + str(credit))



RE: Fruit Machine - ichabod801 - Oct-17-2017

Line 37 should use 'and' instead of 'or'. Think about it: for that to be False, start would have to be 'quit' and 'roll' at the same time, which is impossible (for a string). It's continuing every time through the loop, and never checking the results.

You should also move the if block starting at line 42 and ending at line 44. As it is now, if you have enough money for one last spin, it will just take that money but it won't spin.


RE: Fruit Machine - nilamo - Oct-17-2017

Quote:
while True:
    import random
    credit = 1

Each time you roll, you reset the credit to 1.  If you want that to persist, set it before you start looping.