lundi 21 mai 2018

random.choice has an issue counting its arguments

I have an issue with random.choice in the random module. So here I have a nice looking block of code:

for trap in range(11):
    leftorright = raw_input("")
    if leftorright == "left" or "right":
        leftchoice = random.choice(True, False)
        if leftchoice:
            print "You don't feel anything on your legs, so you think you're okay."
        else:
            print "You feel a sharp pain on your %s leg." %(random.choice("left", "right"))
    else:
        print sorrycommand

So the issue here is that the two random.choice instances (leftchoice = random.choice(True, False) and print "You feel a sharp pain on your %s leg." %(random.choice("left", "right"))) are giving me this error:

Traceback (most recent call last):
  File "main.py", line 408, in <module>
    startmenuchoice() 
  File "main.py", line 404, in startmenuchoice
    room7()
  File "main.py", line 386, in room7
    leftchoice = random.choice(True, False)
TypeError: choice() takes exactly 2 arguments (3 given)

Now, going right to the real thing here: TypeError: choice() takes exactly 2 arguments (3 given)

It says in the error that there are 3 arguments given, but if you take a look at the error and the code, there are clearly only 2 arguments given (the proper amount of arguments needed). Could somebody please help me?

Side notes:

  1. I will provide any other info needed in the comments since I am not very good of thinking of every bit of needed info.
  2. I am using the site repl.it, an online IDE and compiler. Maybe that might have something to do with it?



Aucun commentaire:

Enregistrer un commentaire