5. 数字和数学计算


print "I will now count my chickens:"
print "Hens", 25 + 30 / 6
print "Roosters", 100 -25 * 3 % 4       # “%”是求余符号

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 "What is 3 + 2?", 3 + 2
print "What is 5 - 7?", 5 - 7

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
Roosters 97
Now I will count the eggs:
7
Is it true that 3 + 2 < 5 - 7?
False
What is 3 + 2? 5
What is 5 - 7? -2
Is it greater? True
Is it greater or equal? True
Is it less or equal? False


print "I will now count my chickens:"
print "Hens", 25.0 + 30.0 / 6           #换成浮点数再运行一次
print "Roosters", 100.0 -25.0 * 3 % 4

print "Now I will count the eggs:"
print 3.0 + 2 +1 - 5 + 4.0 % 2 - 1.0 / 4 + 6

输出
I will now count my chickens:
Hens 30.0
Roosters 97.0
Now I will count the eggs:
6.75

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容