input:
demo:
输入一个数,这个数代表从凌晨0点开始计算的分钟数,并计算并输出当前时间
例如:如果输入的是150,那么应该就是凌晨2:30,所以程序输出也是2:30
passed_min=int(input("已经过了多少分钟"))
hours=passed_min//60
passed_min= passed_min % 60
print("那么现在是 ",hours, ":",passed_min)
输出结果:
//input 数值是自己随便输入的。
已经过了多少分钟200
那么现在是 3 : 20
应用知识:input语法输入,通过转成int类型,才能进行加减乘除操作。
注意:算法逻辑得严谨,如果输入的分钟数超过了一天的分钟数,该如何展示?
passed_min=int(input("已经过了多少分钟"))
# 加上天数,用最简单的运算法则实现功能
days=passed_min // 60 //24
hours=(passed_min//60)%24
passed_min= passed_min % 60
print("那么现在是过了 ",days,"天之后的",hours, "小时",passed_min,"分钟")
//输出结果
已经过了多少分钟1442
那么现在是过了 1 天之后的 0 小时 2 分钟
age=input("how old are you?\n")
height=input("How tall are you?\n")
print("You're %s years old,%s meters tall." % (age,height))
//结果:(用%s来接收输出结果)
how old are you?
27
How tall are you?
160
You're 27 years old,160 meters tall.
math
# the number type is integer
print("+ and -:",1+1,1-1,1+2-3)
print("* and /:",2*3,6/3,3*4/2)
# excecute inside a () first
print("( and ):",(2+4)/(1+2))
print("%:",9%3,5%2)
//输出结果
+ and -: 2 0 0
* and /: 6 2.0 6.0
( and ): 2.0
%: 0 1
type
# integer
print(type(2 ** 32),type(2^32))
# folat类型
print(type(4/2),type(4/3),type(4/8))
print(type(1+1),(1+1))
# str
print(type("1"+"1"),("1"+"1"))
print(type("1+1"),("1+1"))
//输出结果
<class 'int'> <class 'int'>
<class 'float'> <class 'float'> <class 'float'>
<class 'int'> 2
<class 'str'> 11
<class 'str'> 1+1