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').

Solution

numbers = 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)
▶ RUN

Output/ Explanation:

Latest Current Affairs 2026 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad