Advertisement
Adehumble

Week5 Coding Exercise 5

Feb 27th, 2020
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.50 KB | None | 0 0
  1. #5
  2. #This program is written to find the difference between the sum of two different number lists
  3.  
  4. #Function Program
  5. def sum_difference(expected_list1,expected_list2):
  6.     answer=sum(expected_list1)-sum(expected_list2)
  7.     print(answer)
  8.  
  9. #Main Program
  10. #The following lines will accepts the first number list
  11. user_list1=[]
  12. while True:
  13.     try:
  14.         n1=int(input("How many numbers do you want to play with in the first list: "))
  15.         break
  16.     except ValueError:
  17.         print("That's a wrong input!\nYou must provide a positive integer. Please, try again.")
  18.         print("\n")
  19.  
  20. for m in range(n1):
  21.     while True:
  22.         try:
  23.             user_num1=int(input("Enter those numbers: "))
  24.             break
  25.         except ValueError:
  26.             print("That's a wrong input!\nYou must provide a positive integer. Please, try again.")
  27.     user_list1.append(user_num1)
  28.  
  29. print("\n")
  30.  
  31. #The following lines will.accepts the second number list
  32. user_list2=[]
  33. while True:
  34.     try:
  35.         n2=int(input("How many numbers do you want to play with in the first list: "))
  36.         break
  37.     except ValueError:
  38.         print("That's a wrong input!\nYou must provide a positive integer. Please, try again.")
  39.         print("\n")
  40.        
  41. for n in range(n2):
  42.     while True:
  43.         try:
  44.             user_num2=int(input("Enter those numbers: "))
  45.             break
  46.         except ValueError:
  47.             print("That's a wrong input!\nYou must provide a positive integer. Please, try again.")
  48.     user_list2.append(user_num2)
  49. print("\n")
  50.  
  51. print("The diference between the sum of", user_list1, "and", user_list2, "is: ")   
  52. sum_difference(user_list1,user_list2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement