221k views
4 votes
Can someone help me with a code

Write a program that generates and prints five random lottery numbers of a three-digit number
between 100 and 999. The three digits in the number are the same. Use only one loop.
it needs to print what's below.
Lottery number1: 333
Lottery number2: 222
Lottery number3: 888
Lottery number4: 777
Lottery number5: 111

User Shackles
by
4.2k points

2 Answers

3 votes

Final answer:

To generate five random lottery numbers of a three-digit number between 100 and 999 using a single loop in Python, you can use the random() function.

Step-by-step explanation:

To generate five random lottery numbers of a three-digit number between 100 and 999, you can use a single loop and the random() function in a programming language like Python. Here's an example code:

import random

i = 0
while i < 5:
num = random.randint(1, 9)
lottery_number = str(num) + str(num) + str(num)
print(f'Lottery number{i+1}: {lottery_number}')
i += 1

This code uses the random.randint() function to generate a random number between 1 and 9 (inclusive), and then concatenates the same digit three times to create the three-digit number. It repeats this process five times using a loop and prints the lottery numbers.

User Neema
by
4.2k points
3 votes

Answer:

lottery number 3

Step-by-step explanation:

User Sarel Foyerlicht
by
4.1k points