Python Forum
random.choice Sensing Nonexistent Argument
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
random.choice Sensing Nonexistent Argument
#1
Hello again lol. As I continue my journey through learning the wonderful language of Python, I've made it to the point where I've started to learn classes. To practice and demonstrate my knowledge and learning of classes, I decided to make a random playing card generator, mostly because a friend I have who is learning Java made one. Below I've listed my code, and below the code I've listed the error statement my IDE prints out when I attempt to run it. 
import random

suits = ['Spade', 'Heart', 'Club', 'Diamond']
values = [2, 3, 4, 5, 6, 7, 8, 9, 10, 'Jack', 'Queen', 'King', 'Ace']

class card:
    'Common base class for all cards'
    def __init__(self, suit, value):
        self.suit = suit
        self.value = value

def drawnCard():
    'Common base function for drawn card'
    suitname = suits[random.choice(0, len(suits))] # here is where I think the error in the code is
    valuename = values[random.choice(0, len(values))] # here as well
    cardDrawn = card(valuename, suitname)
    print cardDrawn

drawnCard()
Error:
/System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6 "/Users/Milli/PycharmProjects/untitled1/Classy Card Generator.py" Traceback (most recent call last):   File "/Users/Milli/PycharmProjects/untitled1/Classy Card Generator.py", line 19, in <module>     drawncard()   File "/Users/Milli/PycharmProjects/untitled1/Classy Card Generator.py", line 14, in drawncard     suitname = suits[random.choice(0, len(suits))] # works like typename[position], but instead of you setting the positon, random.choice chooses the position for you TypeError: choice() takes exactly 2 arguments (3 given) Process finished with exit code 1
The second to last line in the error statement is the one I have trouble understanding, and struggle to find the problem and solve it. 
Error:
TypeError: choice() takes exactly 2 arguments (3 given)
Last time I checked my code, I only inputted 2 arguments to both of my uses of random.choice(), unless len() turns out to be two arguments and not one. Any help that you can give is much appreciated.
Reply


Messages In This Thread
random.choice Sensing Nonexistent Argument - by Millionsunz - Nov-28-2016, 04:00 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  combobox_callback(choice choice part of openfile name (kind of dependency) janeik 9 1,617 Sep-10-2023, 10:27 PM
Last Post: janeik
  random.choice HELP samuelbachorik 4 2,386 Aug-18-2021, 03:24 PM
Last Post: naughtyCat
  Unable to use random.choice(list) in async method spacedog 4 3,600 Apr-29-2021, 04:08 PM
Last Post: spacedog
  Help with a random.randint choice in Python booponion 5 2,928 Oct-23-2020, 05:13 PM
Last Post: deanhystad
  trying to input a variable using random.choice python63 9 3,826 Aug-13-2020, 05:37 PM
Last Post: python63
  Random Choice Operations Souls99 6 3,066 Jul-31-2020, 10:37 PM
Last Post: Souls99
  random.choice() takes two positional arguments, but three were given. ShakeyPakey 5 12,003 May-31-2020, 03:13 PM
Last Post: deanhystad
  SyntaxError: positional argument follows keyword argument syd_jat 3 5,988 Mar-03-2020, 08:34 AM
Last Post: buran
  Using Force Sensing Resistors and sould files with Python learnercoder 1 2,759 Apr-01-2018, 06:45 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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