以下假設變量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))