<p>给定一个字符串S,我们将它的权重定义为元音在字符串中位置的乘积(从1开始)。例:重量(“e”)=1体重(“年龄”)=3;重量(“pippo”)=10</p>
<p>我试过这个:</p>
<pre><code>def weight(s):
vowels = ['a','e','i','o','u']
numbers = []
for c in s:
if c in vowels:
n = s.index(c)+1
numbers.append(n)
result = 1
for x in numbers:
result = result*x
print(result)
</code></pre>
<p>但它只适用于不同的元音。如果字符串中有相同的元音,则数字是错误的。
我错过了什么</p>
<p>谢谢大家</p>