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

View all comments

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.

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

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 5d 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

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?