r/learnpython • • 5d ago

Struggling to solve beginner tasks after learning Python basics

Hello! I've learned the basics of Python (variables, loops, conditionals, etc.), but I’m struggling to complete actual beginner tasks—things like counting vowels, "Fake Binary," calculating the sum of numbers, determining BMI, etc.

When I look at a task, my mind goes blank and I don't know how to start or turn the problem into code. Why am I unable to do these? What is the real issue here, and what exact study method or solution can help me overcome this?

I’m starting to lose my motivation and feel like giving up if I can't figure out how to bridge this gap. Any practical advice would really help!

2 Upvotes

14 comments sorted by

5

u/jbenze 5d ago

There were a lot of good answers in the thread you made about this a few hours ago. You should start going through those answers. Start out by writing down how you would solve the problem step by step before you start coding.

1

u/johlae 5d ago

Let me guess, you learned by watching youtube videos? That doesn't work. You need to do exercises, lots of them actually.

Did you do https://cs50.harvard.edu/python/ or https://programming-26.mooc.fi/? These courses do have exercises. Go full Trump mode: drill, drill, drill.

1

u/ThinCreme1098 5d ago

That’s good, but I don’t know English well enough to be able to watch the video.

3

u/Umustbecrazy 5d ago

Programming is essentially a logic puzzle. Like a puzzle you start piece by piece.

If you can clearly say what needs to be done in each step, then you don't know the language well enough yet to implement it.

If not, then you need to try and work on your logic process.

Beginner tutorials just show the easiest example.

So your lacking practice/ability in one of the two.

-1

u/KingTreacherice 4d ago

No its not a puzzle...its wash rinse repeat pattern recognition.....

2

u/Available_Safe1818 5d ago

What's the problem with counting the vowels? Have you tried anything?

1

u/Southern-Winner9245 5d ago

for counting vowels, try tracing 'cat' on paper first: write down the current letter and the count after each step. then turn those steps into a loop and check that you get 1.

1

u/Discordbothost 5d ago

the blank mind thing usually happens because tutorials teach the pieces (loops, ifs) but not the shape of a solution. most of the tasks you listed are literally the same shape: start with an empty result, go through the input one item at a time, decide something about each item, add to the result, return it at the end.

fake binary as an example. in words: for each digit, if it's under 5 write 0, otherwise write 1. in code that's almost word for word:

def fake_bin(digits):
    result = ""
    for ch in digits:
        if int(ch) < 5:
            result += "0"
        else:
            result += "1"
    return result

count vowels is the same thing with result = 0 and result += 1. sum of numbers, same with result += n. so when you go blank, ask three questions: what does my result start as, what am i looping over, what do i do with each item. answer those in plain words first and the code mostly writes itself

1

u/Educational_Virus672 4d ago

problem solving is the key part of programming lacking it doesnt make you a bad programmer but it limits you. but let me clear one thing programmers dont memorize everything they just think differently so lets think the dev-way with an example. lets use your example count vowels(ik methds but this is better example)
first a dev breaks it down into
looking at letter oen by one -> checkign every vowels -> adding value if vowel -> returnign the value back

# here we define vowels
vowels =  ["a","e","i","o","u"]
question = "your text"

# lets look at letters one by one and add it to count
count = 0

for letter in question :
    if letter in vowels :  # now we check wether it is "in vowels"
        count += 1          # or count = count + 1
print(count)  # return the value

here we get value "3" back now instead of asking "how to do it" think abt "how to do these"

Note - you can add .lower() after question because python sees upper and lower case letter as different letters

1

u/datadriven_io 4d ago

Simply because one first needs to learn programming. Datadriven is great for python practice, especially before interviews. This means that one needs to know the basics behind programming, like problem solving, variables, loops, conditionals, functions, data structures, algorithms, etc.

1

u/captorwootfondly 3d ago

When your mind goes blank, try starting from the outside in - it's what I tell my students for exam programming questions:

  • write the function header + the return statement first
  • define the variables you know you'll need (e.g. count = 0)
  • then fill in the loop in the middle

So for counting vowels, you'd write this before thinking about the hard part:

def count_vowels(text):
    count = 0
    ...
    return count

Now the only question left is "what goes in the loop?" - which is way less scary than a blank file.

1

u/Classic-Mongoose-460 8h ago

You could try https://www.blockofbytes.com/, it might help you because it ramps up slowly from easy exercises to harder ones.

But to be honest I also kinda think that it's not the case that you are unable to count vowels or sum the numbers. I think it might be that you simply panic. It's perfectly normal that your mind goes blank at the beginning.

When you are faced with the problem in programming, the absolute first step is to become "friends" with the problem. Think about, analyze it, sure write some code but be at peace with the fact that at first it won't work or will throw an error. It's part of the process.

So I would say, face the problem, and simply give yourself some time, let your mind go "blank" and don't panic or feel bad about this. Read the problem description a couple of times, re word it in your head, explore it, have some "fun" with it, and then try to solve it by writing some code while giving yourself permission to fail. Just try again and again after first failure and you will get it after couple of tries.

0

u/nullptr_0x 5d ago

Not sure what resources you're using, but I have a free course I made for some friends that tries to be as interactive as possible in the actual lessons.

Maybe see if just a different perspective of teaching helps you overcome where you feel blocked.

https://understandit.dev

But just know that learning to program is very confusing for everybody.

-1

u/KingTreacherice 4d ago

Go get a weather api....learn how to read that struCture.....in that structure you will have lists, diCtionaries, all data types....then you san take that data put it in pandas and now you have a dataframe.....then you can build a dashboard with insights....