Python Forum
Generating a list and a tuple - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Generating a list and a tuple (/thread-8959.html)



Generating a list and a tuple - Truman - Mar-15-2018

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


values = input("Please add some numbers in a row: ")
l = values.split(",")
t = tuple(l)
print(l)
print(t)
Please add some numbers in a row: 1 2 3 4 5 6 7
['1 2 3 4 5 6 7']
('1 2 3 4 5 6 7',)

Please add some numbers in a row: 1234567
['1234567']
('1234567',)

it doesn't split and it doesn't separate elements with comma. Even when I remove comma from the split function it's giving me the same outcome.

I also tried to convert input string into integer with
values = int(input("Please add some numbers in a row: ")) 
but in that case I receive a value error. Could you explain me why?


RE: Generating a list and a tuple - micseydel - Mar-15-2018

The input you're providing doesn't have any commas.


RE: Generating a list and a tuple - Truman - Mar-15-2018

Yes, that's why I did split with
l = values.split(",")
.
Are you saying that this line of code doesn't work?


RE: Generating a list and a tuple - wavic - Mar-15-2018

(Mar-15-2018, 12:09 AM)Truman Wrote: Write a program which accepts a sequence of comma-separated numbers from console and generate a list and a tuple which contains every number.

The input is not formatted as comma-separated values. So you can't split it by a comma because there is no any.