習題3-數(shù)字計算
- 認識python中數(shù)字運算符
- python數(shù)字計算練習
認識python中數(shù)字運算符
+ 加號
- 減號
/ 斜杠 除
* 星號 乘
% 百分號 求余
< 小于號 判斷
> 大于號 判斷
<= 小于等于 判斷
>= 大于等于 判斷
python數(shù)字計算聯(lián)系
# -*- 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
執(zhí)行結果
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