vendredi 17 avril 2020

How do you separate the duplicated from the non-duplicated numbers into two lists by using an if/else statement?

I was able to find a way to compare all of the numbers in the three lists. Should a number be present in all three lists, I would have to add it to the matching_numbers list. If a number doesn’t match any of the other numbers, then I would have to add it to the unique_numbers list. Duplicates found in two of three lists are considered unique numbers, therefore they should go into the unique_numbers list.

list_1 = []

list_2 = []

list_3 = []

matching_numbers = []

unique_numbers = []

countone = 0

counttwo = 0

countthree = 0

exit = 0

import random

name = input("Hello USER. What will your name be?")

print("Hello " + name + ". Welcome to the NUMBERS program.")

amountone = int(input("How many numbers do you wish to have for your first list? Please choose from between 1 and 15."))

while countone != amountone:
  x = random.randint(1, 30)
  list_1 += [x,]
  print(list_1)
  countone += 1

amounttwo = int(input("For your second list, how many numbers do you wish to have? Please choose from between 1 and 15."))

while counttwo != amounttwo:
  x = random.randint(1, 30)
  list_2 += [x,]
  print(list_2)
  counttwo += 1

amountthree = int(input("For your third list, how many numbers do you wish to have? Please choose from between 1 and 15."))

while countthree != amountthree:
  x = random.randint(1, 30)
  list_3 += [x,]
  print(list_3)
  countthree += 1

for a in list_1:
  for b in list_2:
    for c in list_3:
      if a == b and b == c:
        matching_numbers = list(set(list_1) & set(list_2) & set(list_3))
      else:
        unique_numbers = 

Aucun commentaire:

Enregistrer un commentaire