每一种编程语言都包含处理数字和进行数学计算的方法。不必担心,程序员经常撒谎说他们是多么牛的数学天才,其实他们根本不是。如果他们真是数学天才,他们早就去从事数学相关的行业了,而不是写写广告程序和社交网络游戏,从人们身上偷赚点小钱而已。
这章练习里有很多的数学运算符号。我们来看一遍它们都叫什么名字。你要一边写一边念出它们的名字来,直到你念烦了为止。名字如下:
+ plus 加号
- minus 减号
/ slash 斜杠
* asterisk 星号
% percent 百分号
< less-than 小于号
> greater-than 大于号
<= less-than-equal 小于等于号
>= greater-than-equal 大于等于号
有没有注意到以上只是些符号,没有运算操作呢?写完下面的练习代码后,再回到上面的列表,写出每个符号的作用。例如 + 是用来做加法运算的。
1 #-- coding: utf - 8 -- 2 print "I will now count my chickens:" 3 4 print "Hens",25 + 30 / 6 5 print "Roosters", 100 - 25 * 3 % 4 6 7 print "Now I will count the eggs:" 8 9 print 3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 +6 10 11 print "Is it true that 3 + 2 < 5 - 7?" 12 13 print 3 + 2 < 5 - 7 14 15 print "What is 3 + 2?", 3 + 2 16 print "What is 5 - 7?", 5 - 7 17 18 print "Oh, that's why it's False." 19 20 print "How about some more." 21 22 print "Is it greater?", 5 > -2 23 print "Is it greater or equal?", 5 >= -2 24 print "Is it less or equal?", 5 <= -2