Python Forum
Generating a list and a tuple
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Generating a list and a tuple
#1
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?
Reply
#2
The input you're providing doesn't have any commas.
Reply
#3
Yes, that's why I did split with
l = values.split(",")
.
Are you saying that this line of code doesn't work?
Reply
#4
(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.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  function for generating graph bar from list Paulman 4 1,729 Nov-11-2021, 09:00 AM
Last Post: ibreeden
  Removing existing tuples from a list of tuple Bruizeh 4 2,733 May-15-2021, 07:14 PM
Last Post: deanhystad
  list of list to list of tuple? student8 2 2,907 Nov-14-2017, 08:06 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020