Skip to content Skip to sidebar Skip to footer

How To Loop X Amount Of Times Based On User Input

I'm trying to work on this sample problem that asks a user how many power ball tickets they would like generated, and then it does just that for them.. So far, I have the following

Solution 1:

Change for i in num_tickets(): to for i in xrange(num_tickets):

num_tickets is integer. xrange(num_tickets) generates sequence 0, 1, .. num_tickets - 1

Solution 2:

Solution 3:

n=int(input())
for i inrange(0,n):
    n=int(input())

you can enter n values in this loop and it runs n times.

Post a Comment for "How To Loop X Amount Of Times Based On User Input"