-1
randNum = random.randrange (1,3)
    NameMale = ['Noah']
    NameFemale = ['Alyna']
    Job = ['Accountant'] 
    Age = random.randrange (18,81)
    Gender = ['Male', 'Female']
    Company = ['State Farm']
    Event = ['A drunk driver hit me head-on']
    if randNum == 1:
        print ("Hi. I'm {}. I'm {} years old, and I was a(n) {} at {}. That is, until everything changed. One day, {}.").format((random.choice(NameMale)),(random.choice(Age)),(random.choice(Job)),(random.choice(Company)),(random.choice(Event)))

error message:

Traceback (most recent call last):
  File "/home/pi/Scenario Generator.py", line 14, in <module>
    print ("Hi. I'm {}. I'm {} years old, and I was a(n) {} at {}. That is, until everything changed. One day, {}.").format((random.choice(NameMale)),(random.choice(Age)),(random.choice(Job)),(random.choice(Company)),(random.choice(Event)))
  File "/usr/lib/python2.7/random.py", line 275, in choice
    return seq[int(self.random() * len(seq))]  # raises IndexError if seq is empty
TypeError: object of type 'int' has no len()

What does this mean, where is it coming from, and how can I solve it?

Josh D
  • 23
  • 5
  • have a look at https://stackoverflow.com/questions/53162/how-can-i-do-a-line-break-line-continuation-in-python to make the print statement appear on multiple rows for readability. – Anton vBR Jul 11 '17 at 05:05

3 Answers3

2

The call random.randrange(18, 81) returns an integer and not a sequence. So the call to random.choice(Age) will throw an error.

Tague Griffith
  • 3,963
  • 2
  • 20
  • 24
0

As you can see, the error came from module named random.py when you call function random.choice(Age)

The parameter of random.choice() have to be a sequence not an integer.

Check your Age variable one more time

0

Change Age = random.randrange (18,81) to Age = [random.randrange (18,81)]

random.randrage returns number and choice expects sequence.

PrashanthBC
  • 275
  • 1
  • 10