-5

How can I ask from the user to enter a list in Python3,so as every time the program runs,the input list is the mutable data of the program?

For example, number lists,that user maybe enters are:

L1 = [7,9,16,25],L2 = [5,10,15,20],L3 = [10,17,19,24],`L4 = [16,20,20,23] Please write the commensurable commands/statements.

Callan
  • 3
  • 3
  • 1
    The question isn't clear enough. – Sharad Nov 08 '16 at 17:29
  • 1
    t looks like you want us to write some code for you. While many users are willing to produce code for a coder in distress, they usually only help when the poster has already tried to solve the problem on their own. A good way to show this effort is to include the code you've written so far, example input (if there is any), the expected output, and the output you actually get (console output, tracebacks, etc.). The more detail you provide, the more answers you are likely to receive. Check the [FAQ](http://stackoverflow.com/tour) and [How to Ask](http://stackoverflow.com/help/how-to-ask). – Rory Daulton Nov 08 '16 at 17:41
  • I am novice in Python .Thank you for the feedback. – Callan Nov 08 '16 at 18:11

1 Answers1

2

python3's input() now always returns a string instead of evaluating the text as it did in python2.7. this means that you have to convert an input string into the type of data you need. a simple way of achieving this is to prompt the user to enter a list of numbers separated by commas. the resulting string can then be split into a list of strings by calling the string's .split() method. after converting to a list of strings, you can call int() or float() to convert each string into an individual number.

Example:

s = input("enter a list of numbers separated by commas:") #string
l = s.split(",")  #list
n = [int(x) for x in l] #numbers
Aaron
  • 10,133
  • 1
  • 24
  • 40