input()可以讓使用者於程式執行後輸入資料。例如,以下程式可以輸入資料,括號內的「input a:」是輸入提示。
Python將輸入的東西一律視為字串,所以若要進行數值運算,請先用int()函數將字串轉為數值。請鍵入以下程式,並輸入數值、觀察結果。
a = input("input a:")
b = input("input b:")
print(a+b) # 字串相加
a = int(input("input a:"))
b = int(input("input b:"))
print(a+b) # 數值相加
3 5 3 5
35 8
| ID | User | Problem | Subject | Hit | Post Date |
沒有發現任何「解題報告」 |
|||||