I'm defining a function that creates a list with input values. I have 2 questions:
- How to define the list's name (n) from an input?
- How to transform numeric items in float type?
n=name of the list from an input
I've tried to assign the list to n, but after running the function, when writing the list name, it gave me a NameError.
About the 2nd issue, I've tried to turn the input into a float, but it didn't work and the list's numeric items were still strings.
def createlist():
n=input("What's the list's name?"+'\n')
a=input("Insert the list items"+'\n')
l=[a]
while a!='':
b=input('\n')
m=[b]
l=l+m
a=b
l=l[:-1]
print(n,'=',l)
n=l
createlist()
n='List'
List = ['banana', 'apple', 'peach', '4.33', '56.243']
List
NameError: name 'List' is not defined
I expect output of List to be the created list, but it actually gives me a NameError. When writing a number as item it goes into the list as a string, not an int.
I'd like some help. Thanks.