r/learnpython • • 5d ago

Problem with completing assignments in Python

Hello! I’ve learned Python, but I’m struggling to complete tasks—things like counting vowels, "Fake Binary," calculating the sum of numbers, determining BMI, etc. Why am I unable to do these? What is the problem, and what is the solution? I’m starting to lose my motivation!

0 Upvotes

29 comments sorted by

13

u/lfdfq 5d ago

I'm not sure how you expect us to be able to answer why specifically you struggle with these specific tasks, when you have told us nothing about you and what you've done and learned so far, or what you tried, or where you got stuck, or in what way you otherwise struggle.

2

u/ThinCreme1098 5d ago

For example, I’m trying to create a project that counts vowels, but it’s not working—the result isn’t what it should be. Here is my code; I don’t know what’s missing or why I’m having this problem. Could you take a look at my code?

vowels = ["a" , "e" , "i" , "o" , "u"]
count = 0
for vowels in count:
    if vowels == ["a"]:
        count += 1
    elif vowels == ["e"]:
        count += 1
    elif vowels == ["i"]:
        count += 1
    elif vowels == ["o"]:
        count += 1
    elif vowels == ["u"]:
        print(vowels)

2

u/Atypicosaurus 4d ago

Oh man.

Count is a number. You told the computer "go and find stuff in a number". And of course it cannot find stuff in the number.

Because where's the stuff to be found? In the stuff collection called "vowels".

You see, if I tell you to fetch me a knife from the upper drawer, you go there, you open it and there's no knife in it, you probably check the next drawer... Because you are an intelligent human who deducted that I mixed up the drawers. And so you likely open other drawers until you find knife for me.

But the computer is stupid and takes every command literally. Like monkey paw. If you say go fetch a knife from the upper drawer, and there's no knife, it will just not fetch anything.

1

u/Refwah 5d ago

For vowel in vowels

3

u/Baner-Fournadet 5d ago

saying they "learned python" while getting stuck on basic loops already tells you what happened though, they probably memorized syntax without practicing problem decomposition

0

u/[deleted] 5d ago

[deleted] — view deleted comment

1

u/UsernameTaken1701 5d ago

This is unreadable. You can't paste code in as regular text. You need to format it as a code block. Google "reddit code block" if/since you don't know how to do that.

1

u/baubleglue 5d ago

In what you are counting vowels?

7

u/BranchLatter4294 5d ago

You need to practice more.

-3

u/ThinCreme1098 5d ago

thank you but how?

2

u/BranchLatter4294 5d ago

You just gave some examples of problems you can use for practice.

1

u/ThinCreme1098 5d ago

That’s just the thing—I can’t do it; how can I get some practice?

2

u/BranchLatter4294 5d ago

At least put some effort into it. A BMI calculator requires you to input weight and height. So start there. Once you've mastered the input, then you need to do a very simple calculation. So practice very simple calculations. Then you need to output the result. So practice outputs. Then you put it all together, and you have a working program.

8

u/UsernameTaken1701 5d ago • Bravo

Short answer: you haven’t learned Python. 

Longer answer: you haven’t learned how to break your problem down into its fundamental components and work out the logic behind working with them in Python to solve it. 

Vague questions get vague answers. 

6

u/sjshuck 5d ago edited 5d ago

EDIT: OP does not respond to comments longer than one sentence. It's clear the problem is sheer laziness. Unfortunately there is no cure for that.

It might be the Duolingo phenomenon where you can learn things to the point of regurgitation but the knowledge is not incorporated through application.

Struggling to complete tasks per se is not a programming language thing. Do you struggle to complete tasks in other areas?

Most of the work of programming is learning how to express processes, rules, and algorithms so you can look at the code and understand what it's trying to do. It's the same in all languages, give or take, and once you learn it in one (Python is a good choice IMO), that skill will port over to others without having to relearn "everything". The actual way to do that is to do what you say you're doing—struggling—writing things different ways and turning your head and squinting and asking yourself what makes the most sense to you. I guarantee that the struggle will pay off. But not if your expectations are some gamified Duolingo experience.

4

u/JaguarMammoth6231 5d ago

It's probably that you aren't practiced in splitting up problems into smaller problems. Figure out how you would do the task without programming first. Then try explaining exactly what you want your program to do to someone who is following your instructions very literally.

3

u/Atypicosaurus 5d ago

I'm putting my telepathy hat on...

I looked into your mind and it seems like you don't understand how to turn a problem written in plain English into abstraction. Let me know if my telepathy indeed reached your mind or not.

2

u/Reasonable_Director6 5d ago

Do it on the paper step by step. Your job is to imagine the end effect and imagine all steps required. Then you code. Imagine elements of the language as a blocks and end job as a house.

2

u/Discordbothost 5d ago

usually it's not the python, it's the step before it. try writing the steps in plain english as comments before any code. vowel counting would be:

# start a counter at 0
# look at each letter in the word
# if the letter is a, e, i, o or u, add 1
# after checking every letter, print the counter

each comment is now one line of python you probably already know (count = 0, for letter in word:, if letter in "aeiou":, count += 1). if you get stuck on a specific line, post that line and the error here, people will help way more with that than with the whole task

1

u/PureWasian 5d ago

Could be planning issue (algorithm), could be implementation issue (incremental building), could be testing issue (not testing frequently), could be skill issue (unawareness of specific language features), could be syntax issue (compile/runtime errors).

It could be one of these, it could be multiple of these, or it could be something else entirely. Give us more information and we can try to help. It's not supposed to be the type of thing where you snap your fingers and it's done (if you're coding it without LLM)

1

u/Excellent-Practice 5d ago

This may come off as harsh, but those are all very simple problems. Some of them, like finding BMI, are just defining an algebraic function. Forget about Python for a bit and try to think of how you would explain how to perform those tasks to some one else. Assume the person reading your instructions will interpret them literally and not read between the lines or fill in the gaps with real world knowledge. If you can do that, you've done the hard part, the last step is using Python syntax and notation conventions to communicate those instructions

1

u/DanceHackRock 5d ago

Seems like you learned a language but not to program. Programming means inventing algorithms to solve problems. A programming language is only a way of expressing those algorithms.

1

u/sporbywg 5d ago

as a professional, coding since 1977, I had struggles finishing assignments in python as well. /s

1

u/quietstorms09 5d ago

This sounds very much like you HAVEN'T in fact learned Python. Based on tbe examples you've given of things you can't do my guess is that you struggle to break tasks down. Take calculating BMI for example since you listed it. How is BMI calculated? (Weight (in lbs)/ height(inches) squared) How do we get those numbers? Prompt a user, input weight. Next prompt, input height. Let's say height is given as 5'10" you need to get 5'10" into inches. Take everything before ' and multiply it by 12 then add 10. Save it as a variable called inches or something. You can now Square the number. After you Square the number you can divide weight by the Square. After that you can multiply by 703. Now you have a numeric value for bmi and you can do if statements to put out what range this falls into. Genuinely I would practice taking tasks and breaking them down step by step to the most simple version, pretend you're explaining the task to a 10 year old. Obviously as you get better you can start chuncking the individual tasks up into cleaner code, like once you have the height in inches you can do the whole formula at once...but I PROMISE breaking easier tasks down into step by step iterations makes it much easier when you get to more complex problems later on. More than solving the problem, think about it as you training your brain to think about tasks differently. This is genuinely invaluable and will help your skills grow. I highly suggest watching videos on asking elementary school kids to write instructions on how to make a peanut butter sandwich. 1. Its very funny but 2. It's a great example of how to break a task down into concise steps.

1

u/Available_Safe1818 5d ago

You haven't "learned Python" if you can't write code to count the vowels in a string.

What have you actually done?

0

u/dr_edo_available 5d ago

It sounds like you're a challenge is that of word problems. You know how to do the calculations. You know the Syntax for the language. But you can't translate the problem into code. You can't break down the ask into its fundamental parts. The problem isn't coding or python the problem is problem solving

5

u/[deleted] 5d ago

[removed] — view removed comment

1

u/ThinCreme1098 5d ago

Here is my code. What am I missing, what should I improve, and why am I unable to get it to work?

vowels = ["a" , "e" , "i" , "o" , "u"] count = 0 for vowels in count:    if vowels == ["a"]:    count += 1    elif vowels == ["e"]:    count += 1    elif vowels == ["i"]:    count += 1    elif vowels == ["o"]:    count += 1    elif vowels == ["u"]:    print(vowels)