Friday 20 January 2017

TUPLE-LIST BASIC

QUESTION

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

INPUT:

Suppose the following input is supplied to the program: 45,69,78,33,12,98

OUPUT:

Then, the output should be:
['45', '69', '78', '33', '12', '98']
('45', '69', '78', '33', '12', '98')

STEPS I TRY:

1)Try to read input from console using raw input
2)Read about TUPLE(immutable object), from this i came to know what is tuple
3)Read about LIST, from this i came to know what is list and is functions
4)Did coding part

SOULTION 1 :

ConsoleValue=raw_input("Enter the number seprated by comma.. which to be displayed as tuple and list...")
singleValues = (ConsoleValue.split(","))
listValue=list(singleValues)
tupleValue=tuple(singleValues)
print(listValue)
print(tupleValue)

OUTPUT FOR SOLUTION 1:



 DISADVANTAGES I FELT FOR SOLUTION 1:
1) memory usage for variables

SOLUTION 2:

ConsoleValue=raw_input("Enter the number seprated by comma.. which to be displayed as tuple and list...")
print(list((ConsoleValue.split(","))))
print(tuple((ConsoleValue.split(","))))

OUTPUT FOR SOLUTION 2:


ADVANTAGES I FELT FOR SOLUTION 2:

1)memory usage for variable is reduces

POSSIBLE INPUTS I TRIED:

1)INPUT IS NOT SEPARATES BY COMMA


2)INPUT ARE SERATED BY DOT(.)



3)INPUT JUST COMMA(,)



4)JUST ENTER AS INPUT:





No comments:

Post a Comment