在运行python3代码时Hackerearth上的运行时错误NZEC

时间:2017-10-10 10:49:03

标签: python python-3.x input

当我在hackerearth上运行以下代码时,它会给我运行时错误NZEC。

t = input()
vow = ["A","a","E","e","I","i","O","o","U","u"]
while t>0:
    count_vow = 0
    str1 = input()
    for i in range(str1):
        if i in vow:
            count_vow += 1
    print(count_vow)
    t -= 1

任何种类的帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

您期望的第一个输入是一个数值,因此您应该将input()来电包裹在int()中,以便将其存储为数字

您遇到的第二个问题是,您致电for i in range(str1)str1是一个字符串,range()代表数字。只需使用for i in str1:

即可
t = int(input())
vow = ["A","a","E","e","I","i","O","o","U","u"]
while t > 0:
    count_vow = 0
    str1 = input()
    for i in str1:
        if i in vow:
            count_vow += 1
    print(count_vow)
    t -= 1


Test Cases:
# >> denotes input and > denotes output

>> 2
>> nBBZLaosnm
> 2
>> JHkIsnZtTL
> 1