1. 程式人生 > >Python賦值運算符

Python賦值運算符

賦值運算符 Python

以下假設變量a為10,變量b為20:

技術分享圖片

"=" 的作用是把右邊的數值賦值給左邊的變量

示例1編程實現145893秒是幾天幾小時幾分鐘幾秒鐘?

total = 145893

day = total // (24 * 60 * 60)

hour = (total % (24 * 60 * 60)) // (60*60)

minute = (total % (60 * 60)) // 60

second = total % 60

print("%d秒為%d天,%d小時,%d分鐘,%d" % (total, day, hour, minute, second))

技術分享圖片

示例2用戶依次輸入語文、數學、英語分數,輸出總分和平均分?

chinese = int(input("請輸入語文的分數:"))

maths = int(input("請輸入數學的分數:"))

english = int(input("請輸入英語的分數:"))

print("本次考試的總分:%.2f,平均分:%.2f" % ((chinese+maths+english),(chinese+maths+english)/3))

技術分享圖片







Python賦值運算符