Advertisement
Adehumble

Week4 Coding Exercise 16

Feb 22nd, 2020
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.61 KB | None | 0 0
  1. #16
  2. print("This program is written to filter out the odd elements between two lists inputs of ANY TYPE of user choices.")
  3. print("|||||"*24)
  4.  
  5. #I am going to be demonstrating the functionality of this code by filtering out the odd colour choices of my code user and his/her anonymouus friend
  6.  
  7. #The Function Program
  8. def destroy_elements(expected_list1,expected_list2):
  9.     odd_element = []
  10.     for a in range(len(expected_list1)):
  11.         if expected_list1[a] not in expected_list2:
  12.             odd_element.append(expected_list1[a])
  13.     print(odd_element)
  14.    
  15.            
  16. #The lines of codes below make use of list comprehension. It can also be used in the function. 
  17.    
  18. #   print([odd_element.append(expected_list1[a]) for a in range(len(expected_list1)) if expected_list1[a] not in expected_list2])
  19.  
  20.  
  21.  
  22. #My Main Code
  23. user_list1=[]
  24. user_list2=[]
  25. while True:
  26.     try:
  27.         num1=int(input("How many favorite colours do you have? "))
  28.         break
  29.     except ValueError:
  30.         print("Ooopps! That's a wrong input.\nYou must enter a whole number.\nTry again!")
  31.         print("|||||"*24)
  32.        
  33. for n1 in range(num1):
  34.     user_string1=input("Help me with tbose colors: ")
  35.     user_list1.append(user_string1)
  36.    
  37. while True:
  38.     try:
  39.         num2=int(input("How many favorite colours does your best friend have? "))
  40.         break
  41.     except ValueError:
  42.         print("Ooopps! That's a wrong input.\nYou must enter a whole number.\nTry again!")
  43.         print("|||||"*24)
  44.  
  45. for n2 in range(num2):
  46.     user_string2=input("Help me with tbose colors: ")
  47.     user_list2.append(user_string2)
  48.  
  49. print("The odd colour of your best friend relative to your own favorite.colour is: ")
  50. destroy_elements(user_list1,user_list2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement