fruit machine GSCE challenge

17Bardeno :

im sure you have all heard of the GCSE fruit machine challenge. well i am having issues with that, you see when the user spins 3 skulls it doesnt deduct all their credits and when they only spin 2 skulls it doesnt deduct 1 credit. if anyone can help please do credit = 1 import time t = 1

while True:
         import random
         symbols = 'Star' , 'Skull'

         spin = random.choices(symbols,k=1)
         spin2 = random.choices(symbols,k=1)
         spin3 = random.choices(symbols,k=1)
         ask = input('do you want to spin? ')
         if ask == 'yes':
                  credit = (credit - 0.2)
                  credit = (round(credit, 2))
                  print('You now have... ' +str(credit) + ' credit(s).')
                  time.sleep (t)
                  print('** NOW ROLLING **')
                  time.sleep (t)
                  print('You rolled... ' +str(spin) +str(spin2) +str(spin3))
                  time.sleep (t)
                  if (spin == spin2 == 'Skull' or spin == spin3 == 'Skull' or spin2 == spin3 == 'Skull'):
                           credit = (credit - 1)
                           credit = (round(credit, 2))
                           print('Uh Oh! you rolled 2 skulls.... you lost 1 credit sorry!')
                           print('You now have a total balance of... ' +str(credit)+ ' credits!')
                           if credit >= 0.2:
                                    continue
                           else:
                                    print('Sorry! you dont have enough credits.')
                                    break
                  elif spin == 'Skull' and spin2 == 'Skull' and spin3 == 'Skull':
                           credit = (credit - credit)
                           print('You rolled 3 Skulls!! You lost all your credits!')
                           break
                  elif spin == spin2 and spin2 == spin3:
                           credit = (credit + 1)
                           print('You won 1 credit!')
                           print('You now have a total balance of... ' +str(credit)+ ' credits!')
                           if credit >= 0.2:
                                    continue
                           else:
                                    print('Sorry! you dont have enough credits.')
                                    break
                  elif spin == spin2 or spin == spin3 or spin2 == spin3:
                           credit = (credit + 0.5)
                           credit = (round(credit, 2))
                           print('You won 0.5 credits!')
                           print('You now have a total balance of... ' +str(credit)+ ' credits!')
                           if credit >= 0.2:
                                    continue
                           else:
                                    print('Sorry! you dont have enough credits.')
                                    break

                  else:
                           print('Sorry you didnt win anything.')
                           if credit >= 0.2:
                                    continue
                           else:
                                    print('Sorry! you dont have enough credits.')
                                    break
         elif ask == 'no':
                  print('Your total winnings are.... ' +str(credit))
                  break
         else:
                  print('please say yes or no..')
                  continue
Yonlif :

The problem is you are comparing list to string where "Skull" is a string and the variable "spin" is a list of one element. To solve this you can turn "spin" to a string using spin = random.choice(symbols) which will make one choice as a string.

You seem new to python so I also rewrote your code. You are more than welcome to ask questions about it :)

import time
import random

t = 1
credit = 1.0

while True:
    symbols = "Star", "Skull"
    spins = random.choices(symbols, k=3)

    ask = input("Do you want to spin? ")
    if ask == "yes":
        credit -= 0.2

        print(f"You now have... {credit} credit(s).")
        time.sleep(t)
        print("** NOW ROLLING **")
        time.sleep(t)
        print("You rolled... " + " ".join(spins))
        time.sleep(t)
        if sum(spin == "Skull" for spin in spins) == 2:
            credit -= 1
            print("Uh Oh! you rolled 2 skulls.... you lost 1 credit, sorry!")
        elif sum([spin == "Skull" for spin in spins]) == 3:
            credit = 0
            print("You rolled 3 Skulls!! You lost all your credits!")
        elif all(spin == spins[0] for spin in spins):
            credit += 1
            print("You won 1 credit!")
        elif len(set(spins)) != len(spins):
            credit += 0.5
            print("You won 0.5 credits!")
        else:
            print("Sorry you didn't win anything.")

        credit = (round(credit, 2))
        print(f"You now have a total balance of... {credit} credits!")
        if credit >= 0.2:
            continue
        else:
            print("Sorry! You don't have enough credits.")
            break
    elif ask == "no":
        print(f"Your total winnings are.... {credit}")
        break
    else:
        print("Please say yes or no..")
        continue

Good Luck

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=391205&siteId=1