I want to create two lists ("lstA", "lstB") each comprised of 50 random numbers. I then want to compare the two lists and any overlap that is present I want put into a third list ("lstOvrlp"). I then would like to take the length of that third list and place it into a fourth list ("lstC").
Next I want that basic program to loop 10 times (I'll add user input for this part later).
This is the code I have so far:
def main():
import random
lstA = []
lstB = []
lstC = []
lstA = random.sample(range(1, 101), 50)
lstB = random.sample(range(1, 101), 50)
lstOvrlp = set(lstA) & set(lstB)
while len(lstC) <= 10:
print("This is list A:", lstA)
print("\n")
print("This is list B:", lstB)
print("\n")
print("This is the overlap between the two lists:", lstOvrlp)
numinC = len(lstOvrlp)
print("Number in common: ", numinC)
print("\n")
lstC.append(numinC)
print(lstC)
main()
The issue is that rather than spitting out random numbers each time through the loop the program just re-uses the same numbers over and over again resulting in the same overlap numbers and consequently the same lengths in "lstC". Perhaps there is some other function in Random that I just don't know about, but I can't find it.
I'd like there to be a new batch of numbers in "lstA" and "lstB" each time the program loops so that "lstC" ends up with varied entries. I'm trying to get some practice working with data and eventually I'll be running some simple statistics analysis on this information such as averages and what not.
While I can't point out the errors that are here, I can guarantee there are plenty of them so please be patient.
Thanks
Aucun commentaire:
Enregistrer un commentaire