Python Forum
Thread Rating:
  • 2 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fruit Machine
#1
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))
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
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.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020