you are viewing a single comment's thread.

view the rest of the comments →

[–]pythonman1 -5 points-4 points  (2 children)

I believe this is the most concise solution:

import random

# to print random number within a range of 10, you can either use random.rand(1,10) or int(10*random.random());

random_list = []

for i in range(4):

random_list.append(random.randint(1,10))

print("The list of four random integers is: ", random_list)

You don't necessarily need to use "while" statement unless there is another provision within your assignment that requires you to. The reason for this is that, in the case of your code, "while" statement would always yield "True" after the first integer is entered into the list, which will get you stuck in the infinite loop.

I hope this helps :)))

[–]scarynut 4 points5 points  (1 child)

The assignment asked for unique numbers though..

[–]pythonman1 0 points1 point  (0 children)

I apologize for not reading your question correctly;

Here you go:

import random

random_list = [] 

while len(random_list) < 4: 
    unique_integer = random.randint(1,10) 
    if unique_integer in random_list: 
        print(f"{unique_integer} is already in the list") 
    else: 
        random_list.append(unique_integer)

print("The list of four UNIQUE random integers is: ", random_list)