Skip to content Skip to sidebar Skip to footer

How To Repeat A Function In Python (complete Beginner - First Lines Of Code Ever)

I have the following code which I have to build upon (i.e. it can't be written a different way). I know there are other better ways of achieving the end result, but I want to use t

Solution 1:

If you don't need to build up your list you could just print them one at a time:

for _ in range(100):
    print(choice(number_list))

If you want to build your list first you can use a "list comprehension":

choices = [choice(number_list) for _ in range(100)]
print(choices)

Solution 2:

for i in range(100):
    print(choice(number_list))

Post a Comment for "How To Repeat A Function In Python (complete Beginner - First Lines Of Code Ever)"