学习内容:
数字和数学计算
print("I will now count my chickens:")
#计算题
print("Hens",25+30/6)#hens=母鸡
print("Roosters",100-25*3%4)#Roosters=公鸡
print("now i will count the eggs:")
print(3+2+1-5+4%2-1/4+6)
#判断题
print("Is it true that 3+2<5-7?")
print(3+2<5-7)
print("oh,that's why it's False.")
print("How about some more.")
print("Is it greater?",5>-2)
print("Is it greater or equal?",5>=-2)
print("Is it less or equal?",5<=-2)
运行结果
I will now count my chickens:
Hens 30.0
Roosters 97
now i will count the eggs:
6.75
Is it true that 3+2<5-7?
False
oh,that's why it's False.
How about some more.
Is it greater? True
Is it greater or equal? True
Is it less or equal? False
/、//、%三种符号的用法
#打印,双引号和单引号内表示字符串,数字计算时不需要加双引号
print(3/2)#除法
print(3//2)#除法结果取整
print(4%2)#余数