コード例 #1
0
    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
コード例 #2
0
    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
コード例 #3
0
 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
コード例 #4
0
    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
コード例 #5
0
 def play(self):
     return Choice(
         random.randint(1, 3)
     )  # Käyttämällä randint-funktiota arvo end on mukana tulosjoukossa
コード例 #6
0
 def play(self):
     # Käyttämällä random.randint:ä, b (3) on mukana tulosjoukossa
     return Choice(random.randint(1, 3))
コード例 #7
0
 def play(self):
     return Choice(random.randint(1, 3))