Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Defining a input checker for integers
- def input_checker(list1):
- '''
- input: list
- return: Boolean
- Function that takes in a list and returns whether the list consists of only integers
- '''
- ## Elements in the list
- for i in list1:
- try:
- number=int(i)
- ## Return False if value error
- except ValueError:
- return False
- return True
- ## The function to run the code
- def Num_list():
- ## Initialising the loop
- input_loop=True
- while input_loop==True:
- ## User input
- input_usr = input("Enter the integers seperated by spaces. Press X to exit: ")
- ## Splitting the data by spaces
- input_usr = input_usr.split()
- ## Exit code
- if input_usr[0].upper()=="X":
- input_loop=False
- ## Running the required function
- else:
- ## Calling the input checker
- if input_checker(input_usr)==True:
- ## Printing the user input
- print(input_usr)
- new_list=[]
- ## Looping through the list
- for i in range(len(input_usr)):
- for j in range(i+1,len(input_usr)):
- ## Calculating the product and the sum of numbers in the list
- prod=int(input_usr[i])*int(input_usr[j])
- sum1=int(input_usr[i])+int(input_usr[j])
- ## Appending the pairs in the list
- if prod%2==0 and sum1%2==1:
- new_list.append((input_usr[i],input_usr[j]))
- ## Exit the loop
- input_loop=False
- ## printing the required output
- print(new_list)
- else:
- print("Input is incorrect please try again")
- continue
- ## Running the function
- if __name__ == '__main__':
- Num_list()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement