r/pythonhelp • u/Ok_Minute_1156 • Jul 13 '22
why sometimes my code doesnt work?
sport_list = ["weight","bike","soccer ball"]
food_list = ["coffee","pasta","tofu"]
import random
while len(sport_list) != 0 or len(food_list) != 0:
lists_list = [sport_list,food_list]
randomed_list = random.choice(lists_list)
if len(randomed_list) == 0:
if lists_list[0] == randomed_list:
randomed_list = lists_list[1]
else:
randomed_list = 0
randomed_product = random.choice(randomed_list)
print(randomed_product)
randomed_list.remove(randomed_product)
it says: Traceback (most recent call last):
File "C:\Users\ohadb\PycharmProjects\pythonProject3\main.py", line 16, in <module>
randomed_product = random.choice(randomed_list)
File "C:\Users\ohadb\AppData\Local\Programs\Python\Python310\lib\random.py", line 378, in choice
return seq[self._randbelow(len(seq))]
TypeError: object of type 'int' has no len()
2
u/carcigenicate Jul 13 '22
Think about this line:
Do these lines make sense together?: