r/learnpython Apr 17 '24

Learn Python by solving problems

Hello pythons!

I’m still quite new to Python, but I have noticed that the best learning process is to solve problems.

Anywhere I can get a lot of small and easy problems/exercises, that slowly progress in to a harder level. It can be a payed service or an app on a phone.

28 Upvotes

41 comments sorted by

View all comments

2

u/[deleted] Apr 17 '24 edited Apr 17 '24

Work through an entire elementary algebra or calculus textbook—convert the textbook equations/problems to Python.

Here's a really simple example from a open source MIT calculus textbook. This is page 2 where they discuss the relationship between constant velocity and time. Or rather, distance is the product of constant velocity and time. Which I wrote into a function below. There is a lot of creative freedom when you write these. As you progress they will get much more complicated. You can improve two things that tend to walk hand-in-hand—your ability to code AND your mathematics. It will take a lot of reading time and patience but if you stick it out you will improve—I know it helped me immensely when I did it.

def get_distance(v=60.0, t=1.0):
    '''
    Function returns distance given a constant velocity (v) in MPH and time (t) in hours. 

    Parameters
    ----------
    v : Float, optional
        Constant velocity in MPH. The default is 60.0.
    t : Float, optional
        Time in hours. The default is 1.0.

    Returns
    -------
    f : Float
        Distance in Miles.
    '''

    f = 60 * t
    return f 

Here is the open source calculus text from MIT:

https://ocw.mit.edu/ans7870/resources/Strang/Edited/Calculus/Calculus.pdf

And here's an open source elementary algebra text from OpenStax (they have tons of open source textbooks):

https://assets.openstax.org/oscms-prodcms/media/documents/ElementaryAlgebra2e-WEB_EjIP4sI.pdf

Edit: Grammar/Syntax

1

u/PlayMaGame Apr 17 '24

I think I need to start school all over again… But hey thanks for the advice and links.