Python世界里的赋值运算符

时间:2023-03-08 22:35:27
Python世界里的赋值运算符

Python赋值运算符

以下假设变量a为10,变量b为20:

Python世界里的赋值运算符

"=" 的作用是把右边的数值赋值给左边的变量

示例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))

Python世界里的赋值运算符

示例2用户依次输入语文、数学、英语分数,输出总分和平均分?

chinese = int(input("请输入语文的分数:"))

maths = int(input("请输入数学的分数:"))

english = int(input("请输入英语的分数:"))

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

Python世界里的赋值运算符