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)))
Fehlermeldung:
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()
Was bedeutet das, woher es kommt, und wie kann ich sie lösen?Wo ist "Objekt vom Typ 'int' hat keine len()" aus?
werfen Sie einen Blick auf https://stackoverflow.com/questions/53162/how-can-i-do-a-line-break-line-continuation-in-python, um die print-Anweisung in mehreren Zeilen für anzuzeigen Lesbarkeit. –