SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Tony Gaddis
Chapter:
Lists And Tuples
Exercise:
Programming Exercises
Question:2 | ISBN:9780132576376 | Edition: 2

Question

Lottery Number Generator
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 6.) Then write another loop that displays the contents of the list.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

Lottery Number Generator:

#Import header random section
import random
#Initialize the variable name
lotteryNum = []

# Generate random numbers and assign them to list elements
for _ in range(7):
    digit = random.randint(0, 9)
    lotteryNum.append(digit)

# Display the lottery number
print("Lottery Number:")
for digit in lotteryNum:
    print(digit, end=' ')

Executed Output:

Lottery Number:
1 3 9 3 5 7 7 

 

0 0

Discussions

Post the discussion to improve the above solution.