Python Forum
random.choice() takes two positional arguments, but three were given.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
random.choice() takes two positional arguments, but three were given.
#1
Hello.

In Python, I am using the random module. I have used the random.choice() method to randomly pick from two strings:

    import random

    variable = random.choice('string1','string2')
    print(variable)
However, when I run it, the following error occurs:

Error:
TypeError: choice() takes two positional arguments, but three were given.
I have also used

from numpy import random

instead of just

import random

but it still does not work.

How am I able to fix this error? Thank you.
Reply


Messages In This Thread
random.choice() takes two positional arguments, but three were given. - by ShakeyPakey - May-31-2020, 12:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] Class takes no arguments bily071 2 645 Oct-23-2023, 03:59 PM
Last Post: deanhystad
  combobox_callback(choice choice part of openfile name (kind of dependency) janeik 9 1,449 Sep-10-2023, 10:27 PM
Last Post: janeik
  Error TypeError: output_type_handler() takes 2 positional arguments but 6 were given paulo79 1 1,947 Oct-17-2022, 06:29 PM
Last Post: paulo79
  Error: _vhstack_dispatcher() takes 1 positional argument but 9 were given alexfrol86 3 5,828 May-09-2022, 12:49 PM
Last Post: deanhystad
  TypeError: missing 3 required positional arguments: wardancer84 9 10,906 Aug-19-2021, 04:27 PM
Last Post: deanhystad
  random.choice HELP samuelbachorik 4 2,278 Aug-18-2021, 03:24 PM
Last Post: naughtyCat
  Checking the number of arguments a function takes Chirumer 3 2,162 Jul-06-2021, 04:56 PM
Last Post: Chirumer
  TypeError: max_value() missing 2 required positional arguments: 'alpha' and 'beta' Anldra12 2 4,217 May-15-2021, 04:15 PM
Last Post: Anldra12
  Unable to use random.choice(list) in async method spacedog 4 3,443 Apr-29-2021, 04:08 PM
Last Post: spacedog
  Class Takes No Arguments horuscope42 4 4,835 Oct-26-2020, 11:10 PM
Last Post: not_username1234

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020