笨方法学python-习题3-数字计算

习题3-数字计算

  • 认识python中数字运算符
  • python数字计算练习

认识python中数字运算符

+ 加号
- 减号
/ 斜杠 除
* 星号 乘
% 百分号 求余
< 小于号 判断
> 大于号 判断
<= 小于等于 判断
>= 大于等于 判断

python数字计算联系

# -*- coding: utf-8 -*-
print "I will now count my chickens:"

print 'Hens',25+30/6
# 先计算乘除再加减 Hens 30
print "Roosters",100-25*3%4
#先计算25*3=75 75%4=3 100-3 =97 Roosters 97
print "Now I will count the eggs:"

print 3+2+1-5+4%2-1/4+6
#6-5+0-0+6=7


print "Is it true that 3+2<5-7?"

print 3+2<5-7
# False
print "What is 3+2?",3+2
#"What is 3+2? 5
print "What is 5-7?",5-7
#What is 5-7? -2

print "Oh, that's why it's False."

print "How about some more."

print "Is it greater?",5>-2
#True
print "Is it greater or equal?",5>=-2
#True
print "Is it less or equal",5<=-2
#False

执行结果

PS F:\python大师\习题> python .\ex3.py
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
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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 习题0:准备工作 总有一天你会听到有程序员建议你使用 Mac OSX 或者 Linux。如果他喜欢字体美观,他会告...
    KennyP0618阅读 2,255评论 0 1
  • 目录 第一章 1.编程是做什么的 2.为什么学python 3.从hello Word开始 第二章 1.p...
    谢艺俊阅读 666评论 0 5
  • 体验:今天去救援,车坏在高速路口,头一次遇见这种情况,把车推出高速很危险,每台车都不让,核心、人人为己,不想自己有...
    郭家乐阅读 38评论 0 0
  • 也许哪一次在你不知道的时候,你就为之开心不已,无谓之自己。球赛球赛,开心开心。
    木一林森阅读 155评论 0 0
  • ──听樊登老师解读《内向孩子的潜在优势》 内向孩子与外向孩子只是不同,而我们不要刻意去比较,或者刻意去让一种性格屈...
    六爸啦啦啦阅读 262评论 0 0