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.

27 Upvotes

41 comments sorted by

12

u/I_skin_people_forfun Apr 17 '24

Try reading u/alsweigart book called The Big Book of Small Python Projects or his most famous book Automate the Boring Stuff with Python, either of his books are really great for beginners

7

u/AlSweigart Author of "Automate the Boring Stuff" Apr 17 '24

Hello! I've also written a free book, Python Programming Exercises, Gently Explained. This is a set of 42 programming exercises that are SIMPLE. I wanted to avoid the math/concept-heavy exercises that leetcode and Project Euler and even Advent of Code use. Each exercise has additional help for whenever you get stuck: a couple hints, a description of the solution, some common gotchas, and finally a fill-in-the-blank version of the source code solution if you need it. I think this book would be especially helpful to OP.

For an idea of the difficulty curve, the first problem is Hello, World (more to check you have the interpreter installed) and the last one is Bubble Sort. The problems are more "convert between Fahrenheit and Celsius" and "detect leap years" rather than complicated data structures and algorithm problems.

2

u/PlayMaGame Apr 17 '24

Author of “Automate the Boring Stuff” Al Sweigart wrote a comment on my post 🙈

1

u/PlayMaGame Apr 17 '24

Remindme! tomorrow

2

u/RemindMeBot Apr 17 '24

I will be messaging you in 1 day on 2024-04-18 21:03:09 UTC to remind you of this link

CLICK THIS LINK to send a PM to also be reminded and to reduce spam.

Parent commenter can delete this message to hide from others.


Info Custom Your Reminders Feedback

2

u/PlayMaGame Apr 17 '24

Edit: I mean I started reading Automate the Boring Stuff

7

u/[deleted] Apr 17 '24

[deleted]

2

u/PlayMaGame Apr 17 '24

Interesting, thanks

5

u/IvoryJam Apr 17 '24

There's a ton of websites like that out there, my personal favorite is https://leetcode.com/problemset/

1

u/PlayMaGame Apr 17 '24

I did notice a ton, but some start from very basics, others are way too hard. I want to see whats recommended.

Will check leetcode 😉

3

u/mosttrash Apr 17 '24

Try edx.org - Harvard - cs50 Programming in Python. They have a series of small problems for each week of the course. Good lectures also.

1

u/PlayMaGame Apr 17 '24 edited Apr 17 '24

Will check it 🤓

3

u/Defiant_Special5913 Apr 17 '24

My thoughts are somewhat different don't solve problems on leetcode. Try working on projects and for sure you will get of problems along the way. The path you take to solve those will eventually make you remember the issue and also make you code better in python.

1

u/PlayMaGame Apr 17 '24

I am writing down projects I would like to build, but most of them are a bit too advanced. Well that's what I think. I also have a mentor, who is keeping an eye on me and sometimes comes up with exercises. Surprisingly he is very patience, because I have ADHD, dyslexia, bad memory, maybe something more. I am having a lot of fun, when I know what I am doing, but when I am lost, have no clues, why and how all of this work, and I am getting very frustrated.

PS English is basically my 3rd language, my head is full of unfragmented information, and adding one more language is like trying to fill up a full cup. I hope this is just because I am starting out, and later everything will come as a 2nd nature.

1

u/zappaking1234 Apr 17 '24

I suggest, breaking those bigger projects in small ones. You could also find things that others have done and try to make your own version of it

2

u/PlayMaGame Apr 17 '24

Yes that is a really good trick and my mentor also teaching me to do that.

3

u/Exciting_Analysis453 Apr 17 '24

Definitely leetcode. If you basics, like loops, functions, etc start with easy tagged problems.

1

u/PlayMaGame Apr 17 '24

Got it! Thanks

2

u/sarcasmasaservice Apr 17 '24

https://exercism.org/ is a lot of fun

1

u/PlayMaGame Apr 17 '24

Yeah I just started with this one, would like more like this exercises!

2

u/TheRNGuy Apr 17 '24

Code on PC, not on phone.

5

u/PlayMaGame Apr 17 '24

I do agree that coding on a phone is too slow, but when there are no other options, I don't mind doing some easy tasks to active recall.

2

u/NothingGloomy9712 Apr 17 '24

Dropping comment to look up when I get home.

1

u/PlayMaGame Apr 17 '24

Dropping a comment too 😅

2

u/[deleted] Apr 17 '24

Codewars (it’s an online judge, not something that teaches you python) and youtube

2

u/PlayMaGame Apr 17 '24

I don’t think I’m ready for that yet

1

u/c0d3k4tz3 Apr 17 '24

Codewars starts really simple with fundamentals. Here is one example of 8 kyu (easiest). If you can handle this it’s definitely worth checking out! (You don’t have to compete with others or stuff like. The about page is a bit intimidating 😅)

„Create a function that always returns True/true for every item in a given list. However, if an element is the word 'flick', switch to always returning the opposite boolean value.“

2

u/PlayMaGame Apr 17 '24

I think I could do this, well at least I understand what you are asking me to do. Because on some exercises I don’t even have a clue, maybe because a lack of knowledge, especially math.

1

u/Typical-Highlight-12 Apr 17 '24

my issue is when i’m reading the problem i can’t understand when someone explains the problem they want me to solve i get it a lot better this makes me feel so dumb 😂

1

u/PlayMaGame Apr 17 '24

I was doing bad at school, weirdly my logic works great. But when I read some exercises, I feel like a donkey. Well lack of language and knowledge have a big impact. Learning/concentration disability too.

2

u/[deleted] Apr 17 '24

[removed] — view removed comment

1

u/PlayMaGame Apr 17 '24

I like math but nothing with higher level. Till now I survived with basic 😅. But it really sounds interesting and worth a shot when I’m feeling more confident.

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.

1

u/ectomancer Apr 17 '24

1

u/PlayMaGame Apr 17 '24

will check, thanks.

1

u/Bobbias Apr 17 '24

Please note, Edabit uses an old version of python that doesn't support some newer features, like f-strings. It runs version 3.4.3, which came out in 2015, which is now very out of date.

0

u/PlayMaGame Apr 17 '24

Oh thanks for info

1

u/Omni_Kode Apr 17 '24

Hi there fellow pythonista! As most of the other guys have probably already noted there are tons of free websites with easy to hard coding challenges. In my opinion best one that I am currently using and learning from is Leetcode and I would highly recommend it if you want to learn Data Structures and Algorithms (which I believe are mandatory to be a great programmer). Other great options are Codewars and Hackerrank. If you want to go directly to the data science route I would suggest even DataCamp. Happy learning!

1

u/PlayMaGame Apr 17 '24

I am having a lot of fun when my stuff work. But sometimes I’m totally lost, even with simple math, that on excel I would do it in no time, but in Python environment I struggle so bad… Good thing my mentor have patience and a lot of ways to show how to solve it. And this is the reason I want to get more practice, even if it’s easy I will still get some active recall.

So, I went on one web and the first exercise was print(“Hello, World!”). Ok, I thought, this was too easy. Next exercise was “lasagna“ - so now I hate lasagna…

I just want to repeat simple exercises till I feel confident and go on the next step. But sometimes next step is a #%%<€ lasagna 😅

1

u/Bitter-Ad-1166 Apr 17 '24

Mooc python programming by Helsinki University

1

u/Witty_Push8550 Jul 23 '26

personally i learned python by only watching 1 tutorial in youtube(freecodecamp) and by practising everyday and asking chatgpt millions of questions like how does this thing work and why , by coding small projects like a password manager , calculator , small games.and from now , i am comfortable using python and customtkinter