Programming Examples
Write a program which accepts a sequence of comma-separated numbers from console and generate a list and a tuple
Write a program which accepts a sequence of comma-separated numbers from console and generate a list and a tuple which contains every number. Suppose the following input is supplied to the program: 34, 67, 55, 33, 12, 98. Then, the output should be: ['34', '67', '55', '33', '12', '98'] ('34',67', '55', '33', '12', '98').
Solutionnumbers = input("Enter comma-separated numbers: ")
# Convert input into a list
num_list = numbers.split(",")
# Convert the list into a tuple
num_tuple = tuple(num_list)
# Display the results
print("List :", num_list)
print("Tuple:", num_tuple)
Output