máquina de frutas desafío GSCE

17Bardeno:

Estoy seguro de que todos hemos oído del desafío máquina GCSE fruta. Bueno, yo estoy teniendo problemas con eso, que se ve cuando el usuario hace girar 3 cráneos es imposible deducir todos sus créditos y cuando sólo giran 2 cráneos, duerma deducir 1 crédito. si alguien puede ayudar por favor el crédito = 1 importación tiempo 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:

El problema es que está comparando lista stringla que "Skull" es una cadena y el "giro" variable es una lista de uno de los elementos. Para solucionar esto se puede convertir "giro" en una cadena mediante spin = random.choice(symbols)lo que hará que una opción como una cadena.

Pareces nuevo en Python, así que también volvió a escribir su código. Usted es más que bienvenido a hacer preguntas al respecto :)

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

Buena suerte

Supongo que te gusta

Origin http://10.200.1.11:23101/article/api/json?id=392513&siteId=1
Recomendado
Clasificación