Advertisement
simmyio

bootcamp_code

Oct 23rd, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. # Simran Modi (ID: 29602610)
  2. # created: 24/oct
  3. #
  4. # Task:
  5. # Read a list of integers from user input.
  6. # Find all pairs of numbers in the list whose product is even and whose sum is odd.
  7. # Print out a formatted list of the pairs.
  8.  
  9. # receiving input
  10. num = input("Input numbers with a single space in between and press enter when done: ")
  11. num = num.strip("\n").split(" ")
  12. num = [int(x) for x in num]
  13.  
  14. # calculating which pairs are valid
  15. output_lst = []
  16. for num1 in num:
  17.     for num2 in num:
  18.         if (num1*num2)//2 % 0 and (num1+num2)//2 % 1:
  19.             output_lst.append((num1,num2))
  20.  
  21. # printing output
  22. for i in range(len(output_lst)):
  23.     print("Pair {}: {},{}".format(i+1,output_lst[i][0],output_lst[i][1]))
  24.  
  25. # end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement