Zerojudge 基礎題庫a021 大數運算(Python)


eval()真是太好用了~ 只是要排除除法的問題有點煩,Python好棒!

程式碼:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
while 1:
    try:
        x = input()
    except:
        break
    y = x.split()
    if y[1] == "/":
        print(int(y[0]) // int(y[2]))
    else:
        print(eval(x))    

    

留言

這個網誌中的熱門文章

Zerojudge 基礎題庫a004 文文的求婚 (Python)

Zerojudge 基礎題庫a002 簡易加法