2017-10-10 132 views
0

當我在hackerearth上運行下面的代碼時,它給了我運行時錯誤NZEC。在運行python3代碼時在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 

任何排序的幫助,將不勝感激。

+0

您使用什麼輸入?什麼是錯誤的堆棧跟蹤? – AK47

+0

以下是輸入 nBBZLaosnm JHkIsnZtTL –

回答

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