Design a program that generates a seven-digit lottery number. The program should generate seven random numbers, each in the range of 0 through 9, and assign each number to a list element. (Random numbers were discussed in Chapter 5 (Links to an external site.).) Then write another loop that displays the contents of the list

Respuesta :

Answer:

In Python:

import random

lotterylist = []

for number in range(7):

   lotterylist.append(random.randint(0,9))

   

for number in lotterylist:

   print(number, end = ', ')

Explanation:

This line imports the random library

import random

This line creates an empty list

lotterylist = []

The instructions in this loop will be performed 7 times

for number in range(7):

This line generates a random number between 0 and 9 (inclusive) and then appends the number into lotterylist

   lotterylist.append(random.randint(0,9))

This iterates through lotterylist    

for number in lotterylist:

This prints the content of the list on a line (seperated by comma)

   print(number, end = ', ')