有人可以解释一下这是如何工作的吗?

乘风 python 190

原文标题Can somebody please explain how this works?

我是 Python 新手,我一直在尝试编写基本程序来理解它。我看到了这个程序,它计算元音的数量,但我不太明白它是如何工作的?我已经把它放在代码可视化器中,但那里什么也没有?有人可以解释我如何输入一个单词来返回计数吗?或者我可以在哪里添加一行要求输入的代码?如果这个问题很愚蠢,我提前道歉。我才刚刚开始。

这是我找到的代码:-

count = 0    

def count_vowel(word):   
    vowels = 'aeiouAEIOU'    
    for i in range(word):    
        if i in vowels:    
            count = count + 1    
return count

原文链接:https://stackoverflow.com//questions/71918966/can-somebody-please-explain-how-this-works

回复

我来回复
  • Alan Shiah的头像
    Alan Shiah 评论

    如果你想让某人能够在终端中输入一些东西,你需要使用input()功能。例如:

    word = input("Type the word: ")
    

    然后你可以在终端打印出来,通过count_vowel函数查看返回值。例如:

    print(count_vowel(word))
    
    2年前 0条评论