def play(self): choice = Choice.NONE while choice == Choice.NONE: try: choiceInt = int( input("Give your choice (1=Rock, 2=Paper, 3=Scissors) ")) choice = Choice(choiceInt) except ValueError: print("Illegal input, give a number between 1 and 3") choice = Choice.NONE except KeyboardInterrupt: raise KeyboardInterrupt except: print("Unknown error, please write a bug report.") choice = Choice.NONE return choice
def play(self): #Käyttäjän valinta tallennetaan tähän muuttujaan. choice = Choice.NONE while choice == Choice.NONE: try: choiceInt = int( input("Give your choice (1=Rock", "2=Paper", "3=Scissors): ")) choice = Choice(choiceInt) except ValueError: print("Illegal input, give a number between 1 and 3") choice = Choice.NONE except KeyboardInterrupt: raise KeyboardInterrupt() except: print("Unknown error!") return choice
def play(self): choice = Choice.NONE while choice == Choice.NONE: try: choice = Choice( int(input("Give your choice (1=Rock, 2=Paper, 3=Sicssors): "))) if choice.value <= 0 or choice.value > 3: choice = Choice.NONE except ValueError: print("Invalid input, give a number between 1-3") choice = Choice.NONE except (KeyboardInterrupt, SystemExit): print("Abort execution") raise # Kaataa sovelluksen except: print("Unknown error") choice = Choice.NONE return choice
def play(self): # Käyttäjän valinta tallennetaan tähän muuttujaan. NONE kuvaa sitä, että käyttäjä ei ole vielä tehnyt valintaa choice = Choice.NONE while choice == Choice.NONE: try: choiceInt = int( input("Give your choice (1=Rock, 2=Paper, 3=Scissors): ")) choice = Choice(choiceInt) except ValueError: print("Illegal input, give a number between 1 and 3") choice = Choice.NONE except KeyboardInterrupt: raise KeyboardInterrupt() except: print("Unknown error! Please write a bug report.") choice = Choice.NONE return choice
def play(self): return Choice( random.randint(1, 3) ) # Käyttämällä randint-funktiota arvo end on mukana tulosjoukossa
def play(self): # Käyttämällä random.randint:ä, b (3) on mukana tulosjoukossa return Choice(random.randint(1, 3))
def play(self): return Choice(random.randint(1, 3))