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)
Output

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad