def toNumbers(strList):
    for char in strList:
       return strList[0:len(char)]
       

def main():
    sttr = ['120','125']
    print(toNumbers(sttr))
main()

The output is:


I want the output to read:
120 125 <-- without the brackets and quotes


I'm supposed to take a list of numbers (as strings) and simply return the same
numbers (not as strings)

Why wouldn't you just want the list??? Is it just a matter of printing? If not why not just return a list of integers??

>>> def renum(lis):
	return [int(num) for num in lis]

>>> a=['1','2','3']
>>> 
>>> b=renum(a)
>>> b
[1, 2, 3]

Why wouldn't you just want the list??? Is it just a matter of printing? If not why not just return a list of integers??

>>> def renum(lis):
	return [int(num) for num in lis]

>>> a=['1','2','3']
>>> 
>>> b=renum(a)
>>> b
[1, 2, 3]

Here's the words from "Python Programming: An Introduction to Computer Science"

Ch 6, programming exercise 13:

13. Write and test a function to meet this specification:

toNumbers(strList) strList is a list of strings, each of which represents a number. Modifies each entry in the list by converting it to a number.

Comments
you don't belong on Daniweb

Here's the words from "Python Programming: An Introduction to Computer Science"

Ch 6, programming exercise 13:

13. Write and test a function to meet this specification:

toNumbers(strList) strList is a list of strings, each of which represents a number. Modifies each entry in the list by converting it to a number.

right, you are modifying each item in the list into a number instead of a string, and returning a list of numbers INSTEAD of a list of strings.

Edited 5 Years Ago by pyguy62: n/a

This article has been dead for over six months. Start a new discussion instead.