Unable to repeat code according to user input in python
Question: I started programming a week ago and I decided I should write a program that
randomly assigns the numbers for the european lottery. I have a working script
that gives the 5 numbers and 2 stars that make a bet. However, I would like
the program to print as many bets as the user would like without having to run
the program multiple times. I tried to create a class that would be
instantiated as many times as the ones the user would require, but it didn't
work. This is the script I have as of now:

    
    
    import random
    
    print "This program doesn't increase the chances of winning the lottery!"
    numbers[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50]
    
    stars=[1,2,3,4,5,6,7,8,9,10,11]
    
    a=random.sample(numbers, 5)
    
    a.sort()
    
    b=random.sample(stars, 2)
    
    b.sort()
    
    print "The numbers are", a
    
    print "The stars are", b
    

I understand that to get input from the user I need to use raw_input("Enter
number of bets you want here") but then I have no idea how to use that input
to repeat the code. Also, if somebody knows how to make the lists shorter,
like instead of having to write every number from 1 to 50 just write like 1-50
I would be grateful to know how. Sorry for bad english and thanks in advance.


Answer: Put your code in a loop.

    
    
    import random
    numbers = range(1,51)  # [1,2,3,... 49,50]
    stars = range(1,12)    # [1,2,3,... 10,11]
    
    def makeNumbers(plays):
        for i in range(plays):  # makes numbers and stars i times
            a = sorted(random.sample(numbers, 5))
            b = sorted(random.sample(stars,2))
            print 'numbers: ', a
            print 'stars: ', b
    

Testing the function

    
    
    >>> makeNumbers(3)
    numbers:  [3, 25, 40, 41, 47]
    stars:  [8, 11]
    numbers:  [22, 25, 42, 47, 50]
    stars:  [5, 9]
    numbers:  [6, 23, 34, 40, 44]
    stars:  [5, 7]
    

