Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

Abraxas Group Title

Who could help me to understand the behavior of Python in this function? I'm trying to convert into integers some numeric strings inside a list. Numbers = ('1', '2', '3', '4') def StrToInt(x): for i in x: print i int(i) I think it doesn't work because function assign a value to a local variable. But, if a try something like: def StrToInt(x): for i in x: print i int(i) return x or def StrToInt(x): global x for i in x: print i int(i) both functions doesn't work either.

  • 2 years ago
  • 2 years ago

  • This Question is Closed
  1. snark Group Title
    Best Response
    You've already chosen the best response.
    Medals 3

    numbers = ['1' ,'2' ,'3'] # our list of numeric strings def toInt(x): # a function which will use x, here a list of strings a = [ ] # create an empty list to hold our integers for n in x: # for each entry in the list x a.append(int(n)) # put the int value of n into our list return a # return our list of integers b = toInt(numbers) # let's test it print(b) [1,2,3] # Surprise!

    • 2 years ago
  2. andrew.m.higgs Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Yes. As Snark says. You need to add the converted strings to a list to be returned.

    • 2 years ago
  3. Abraxas Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Nice Snark!!! Thank a lot!!!! Take your medal. You deserve a lot of it!

    • 2 years ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.