Answer to Question #318574 in Python for Dhea M. Maddela

Question #318574

Develop a Python application that will randomly select n integers from 1 to 45 without repetitions.


Sample Output:


How many numbers? 6

6 randomly selected nos.

[33, 13, 24, 22, 38, 34]



I need the code to have an output stated above.


1
Expert's answer
2022-03-26T14:01:58-0400

The following program randomly selects n integers from 1 to 45 without repetition:

# Create a list of random numbers without repetition
import random

# Generate 6 unique random numbers within a range without repetition
n = int(input("How many numbers? "))

number_list = random.sample(range(1, 46), n)
print(number_list)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS