Question

In: Computer Science

Write a program which accepts a sequence of comma-separated numbers from console and generate a list...

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'] and ('34',67', '55', '33', '12', '98'). Input can be comma separated in one line.

Solutions

Expert Solution

sequence = input("Enter Comma Separated numbers : ")

# removing spaces in sequence
sequence = sequence.replace(" ","")

# splitting comma separated values
sequence = sequence.split(",")

# converting sequence to list
n1 = list(sequence)

# converting sequence to tuple
n2 = tuple(sequence)

# printing list and tuple
print("List  : ",n1)

print("Tuple : ",n2)

Code

Output


Related Solutions

Write a program which accepts a sequence of comma-separated numbers from console and generate a list...
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'] and ('34',67', '55', '33', '12', '98').
In this exercise, you’ll write a program that accepts a person’s birth date from the console...
In this exercise, you’ll write a program that accepts a person’s birth date from the console and displays the person’s age in years. To make that easier to do, we’ll give you a class that contains the code for accepting the birth date. The console output for the program should look something like this: f Welcome to the age calculator. j Enter the month you were born (1 to 12) : 5 Enter the day of the month you were...
Write a program in python language, which accepts 2 numbers and a + sign (for addition)...
Write a program in python language, which accepts 2 numbers and a + sign (for addition) A sign - (for subtraction) A sign * (for multiplication), / (for division) Then calculate and to display the result of the operation he chose with the two numbers. Displaying the appropriate message
specifications for Tasks: 1. Write a program which accepts a list of integers which may contain...
specifications for Tasks: 1. Write a program which accepts a list of integers which may contain duplicated integers, and which outputs the input list as a sorted list in ascending order without duplication You can use either Ruby, C, C++, C# or Java to implement your program (referred to as P). 2. Design a test suite of 10 test cases (referred to as TC). Each test case has not more than 20 integers. 3. Test P against TC to make...
Write a program in Java which performs the sort operation. The main method accepts ten numbers...
Write a program in Java which performs the sort operation. The main method accepts ten numbers in an array and passes that to the method sort. The method sort accepts and sorts the numbers in ascending and descending order. The method display shows the result. You can use integers or floating point numbers.
Write a MIPS program that will ask the user to enter two numbers at the console...
Write a MIPS program that will ask the user to enter two numbers at the console and pass the values to a function that does multiplication
2-Find the critical numbers of the function. (Enter your answers as a comma-separated list. Use n...
2-Find the critical numbers of the function. (Enter your answers as a comma-separated list. Use n to denote any arbitrary integer values. If an answer does not exist, enter DNE.) f(θ) = 6 cos(θ) + 3 sin2(θ) 3- Consider the following. f(x) = x5 − x3 + 9,    −1 ≤ x ≤ 1 (a) Use a graph to find the absolute maximum and minimum values of the function to two decimal places. maximum     minimum (b) Use calculus to find the exact...
Write RTL code to design a sequence generator which will generate the sequence : 0,0,1,0,1,1 and...
Write RTL code to design a sequence generator which will generate the sequence : 0,0,1,0,1,1 and repeat .  (FSM shouldn't be used in RTL) 
In a program, write a function that accepts two arguments: a list, and a number n....
In a program, write a function that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display all of the numbers in the list that are greater than the number n. The program should ask for a list of numbers from the user as well as a value (a, b, c)--> inputs from user. After that, each number in that list should be compared to that value (a or b or...
Write a python program that asks the user to enter a string containing numbers separated by...
Write a python program that asks the user to enter a string containing numbers separated by commas, e.g., s = '1.23,2.4,3.123', Your program should then calculate and print the sum of the numbers entered. Hint: you need to iterate over the string searching for the commas, i.e. their index. The first number is obtained by slicing between the start of the string and the index of the first comma. The second number is between the last comma and the next...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT