(Math: combinations) Write a program that prompts the user to enter 10 integers and displays all the combinations of picking two numbers from the 10.
Program Code:
from itertools import combinations
# Prompt the user to enter 10 integers separated by spaces
num = input("Enter 10 integer numbers: ")
# Convert the input string to a list of integers
numbers = [int(num) for num in num.split()]
# Get all combinations of picking two numbers from the list
combinationsNums = list(combinations(numbers, 2))
# Display the combinations
print("All combinations of picking two numbers from the list:")
for combination in combinationsNums:
print(combination)
Executed Output:
Enter 10 integer numbers: 2 4 6 8 10 5 10 15 20 1
All combinations of picking two numbers from the list:
(2, 4)
(2, 6)
(2, 8)
(2, 10)
(2, 5)
(2, 10)
(2, 15)
(2, 20)
(2, 1)
(4, 6)
(4, 8)
(4, 10)
(4, 5)
(4, 10)
(4, 15)
(4, 20)
(4, 1)
(6, 8)
(6, 10)
(6, 5)
(6, 10)
(6, 15)
(6, 20)
(6, 1)
(8, 10)
(8, 5)
(8, 10)
(8, 15)
(8, 20)
(8, 1)
(10, 5)
(10, 10)
(10, 15)
(10, 20)
(10, 1)
(5, 10)
(5, 15)
(5, 20)
(5, 1)
(10, 15)
(10, 20)
(10, 1)
(15, 20)
(15, 1)
(20, 1)