他說不能夠用eval寫,所以我寫了這串程式,但是它出現了
RE:您的程式被監控系統中斷,可能是程式無法正常結束所導致。
--------------------------------------------------------------------------------
import operator
try:
while True:
time = input().replace("hour", " 3600000 ").replace("h", " 3600000 ").replace("m", " 60000 ").replace("min", " 60000 ").replace("s", " 1000 ").replace("ms", " 1 ").strip().split()
if not time:
break
time_list = [int(t) for t in time]
result_list = []
for i in range(0, len(time_list), 2):
result = operator.mul(time_list[i], time_list[i + 1])
result_list.append(result)
print(sum(result_list))
except EOFError :
pass
建議你寫好之後用範例輸入自己測試看看