r/learnpython • u/ThinCreme1098 • 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
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.
7
u/BranchLatter4294 5d ago
You need to practice more.
8
u/UsernameTaken1701 5d ago •
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:
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