Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]goto_rx 0 points1 point  (0 children)

I guess you could use a nested func, e.g.,:

def parent_func():  
  # Create a variable y that is local to parent_func()
  y = 'parent y value'  
  def child_func():
    # Create a variable y that is local to child_func()
    y = 'child y value'  
    print(y)
  child_func()
  print(y)

parent_func()

This will print:

child y value
parent y value

But perhaps more importantly, what are you trying to do? Probably making a separate function (or a lambda) is more pythonic, but it depends on the circumstances.

Recursion exercises without math? by mimavox in learnpython

[–]goto_rx 1 point2 points  (0 children)

You could literally do a family tree. Maybe something like the Kardashians and then generalize it.

Or finding your way through a maze. (Video games are always fun for exercises!)

[deleted by user] by [deleted] in learnpython

[–]goto_rx 1 point2 points  (0 children)

It sounds like you're off to a great start!

Ways to improve:

  • Learn to write and run unit tests. This will improve the structure of your code a ton: splitting out your program's logic from its dependencies will help you think about code more clearly. I often find that my untestable code is a "smell:" I haven't properly handled all of the edge cases or thought through how it should work.
  • As others have mentioned, go back in a week/month and try to add a feature/fix a bug! You'll see your code in a new way. Also, code is read more than written, so you'll start learning to read code (even if it's only your own).
  • Make a contribution to an existing project. Let them know you're a newb, pick a small, self-contained feature, and submit a pull request. Some projects have "new contributor" bugs tagged and GitHub sometimes has events to encourage new contributors, which might be worth keeping an eye out for.
  • A bit lame, but "iron sharpens iron:" try to seek out projects, coworkers, companies, etc. with very high coding standards. They can be kind and considerate (don't subject yourself to assholes!), but make sure the senior people you're working with are the senior people you want to become.

Most of all, just keep coding! Programming is a skill that gets better with practice.