笨方法学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

你可能感兴趣的:(笨方法学python-习题3-数字计算)