我建立爲一個谷歌foobar的該計數列表中的某個字符的量的函數,它創建這個錯誤,類型錯誤:不支持的操作數類型(一個或多個),用於DIV:「STR」和「INT」 [線14]
TypeError: unsupported operand type(s) for div: 'str' and 'int' [line 14]
這是代碼
def answer(s):
sl2 = []
ol = '10'
if(len(s) != 0):
if(len(s) > 200):
print("That is too long")
else:
s = " ".join(s[i:i+1] for i in range(0, len(s), 1))
sl = s.split()
sl_a = sl.count('a')
sl_b = sl.count('b')
sl_c = sl.count('c')
smallest_int = min(sl_a, sl_b, sl_c)
final_amount = ol/smallest_int #line 14 (the problem)
print(final_amount)
answer(raw_input('Describe the M&Ms'))
我不知道,如果這只是谷歌的foobar的編譯器或我有限的知識蟒蛇。
嘗試改變3行至O1 = 10而不「」,在劃分的字符串「10」到整數smallest_int – Skycc
用'/'操作者與Python2和Python3行爲不同當心。 3/2 = 1與Python2和3/2 = 1.5與Python3 –
爲什麼不直接計數輸入字符串中的字符? –