三、数字和数学计算
数学运算符:
+ plus
- minus
/ slash
* saterisk
% percent
< less-than
> greater-than
<= less-than-equal
>= greater-than-equal
运算优先级:parenthese > exponents > multiplication > division > addition > subtraction(括号>指数>乘>除>加>减
输入:
print('I will now count my chickens:')
print('Hens',round(25 + 30 / 6))
print('Roosters',100 - 25 * 3 % 4)
print('Now I will count the egges:')
print(round(3 + 2 +1 - 5 + 4 % 2 - 1 / 4 + 6))
print("What is 3 + 2 ?",3 + 2)
print("What is 5 - 7 ?",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
Roosters 97
Now I will count the egges:
7
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
% 在py中是余数符号
x 除以 y 余 J,(100 / 16 余 4),% 运算的结果就是J(4)的这部分