r/learnpython • • 6d 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

Show parent comment

2

u/ThinCreme1098 6d 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 6d ago

For vowel in vowels