0

A task i have been set is to create a program that will help people pick random numbers for the lottery and i have no clue where to start.The program must:

  • Allow players to select between 1 - 5 lines.
  • 6 number on each line.
  • Each number must be between 1-49.
  • And an option to repeat.

This is all i have so far:

    lines=int(input("how many lines would you like?"))
    for i in range (0,lines):
         import random
    lotterynumbers = []
     x = 0

     while x < 6:
         lotterynumbers.append(random.randint(1, 49))
         x += 1
     lotterynumbers.sort()
     print (lotterynumbers)

Please help.

4

1 回答 1

1

Here, this should help:

from random import randint as rand_number

def create_lotter_numbers(amount=6):
    return [rand_number(1,49) for i in range(amount)]

def get_user_input(prompt="how many lines would you like? "):
    return int(input(prompt))

Example of use:

>>> a = get_user_input()
how many lines would you like? 5
>>> for i in range(a):
    create_lotter_numbers()


[47, 22, 4, 7, 41, 16]
[12, 30, 36, 1, 39, 10]
[7, 19, 7, 13, 1, 17]
[5, 26, 9, 49, 32, 22]
[32, 30, 5, 34, 45, 6]

About limiting the user input, repetition, validity etc... that you can solve on your own. This answer is just here so that the underlying code is not faulty like you have posted.

于 2013-07-11T15:56:08.097 回答