以下假设变量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))