Hello,
I have a list. start_list = [1,2] and a random_list[]
My goal is to find 4 random numbers where the 2 first numbers are the same as my start_list.
I came up with that code:
The thing is i have to click on run to get a new series of random numbers. Is there a way i can make the process automatic so it looks automatically for my 4 random numbers where the number 1 and 2 are in order of the list, just like in the output.
Probably using sort() but i cant seem to find the exact combination of words on google to get the answer i want and english is not my native language.
Thank you
I have a list. start_list = [1,2] and a random_list[]
My goal is to find 4 random numbers where the 2 first numbers are the same as my start_list.
I came up with that code:
import random random_list = [] start_list = [1,2] for i in range(4): num1 = random.randint(1,2) random_list.append(num1) if num1 == start_list: print ("RL", num1) else: print ("SL", start_list) print(random_list)
Output:SL [1, 2]
SL [1, 2]
SL [1, 2]
SL [1, 2]
[1, 2, 2, 1]
Why is it not returning RL [1.2] ? After all 1,2 are in the random_list and begins by 1 and 2?The thing is i have to click on run to get a new series of random numbers. Is there a way i can make the process automatic so it looks automatically for my 4 random numbers where the number 1 and 2 are in order of the list, just like in the output.
Probably using sort() but i cant seem to find the exact combination of words on google to get the answer i want and english is not my native language.
Thank you