每一種編程語言都包含處理數(shù)字和進(jìn)行數(shù)學(xué)計(jì)算的方法。不必?fù)?dān)心,程序員經(jīng)常撒謊說他們是多么牛的數(shù)學(xué)天才,其實(shí)他們根本不是。如果他們真是數(shù)學(xué)天才,他們早就去從事數(shù)學(xué)相關(guān)的行業(yè)了,而不是寫寫廣告程序和社交網(wǎng)絡(luò)游戲,從人們身上偷賺點(diǎn)小錢而已。
這章練習(xí)里有很多的數(shù)學(xué)運(yùn)算符號。我們來看一遍它們都叫什么名字。你要一邊寫一邊念出它們的名字來,直到你念煩了為止。名字如下:
有沒有注意到以上只是些符號,沒有運(yùn)算操作呢?寫完下面的練習(xí)代碼后,再回到上面的列表,寫出每個(gè)符號的作用。例如 + 是用來做加法運(yùn)算的。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | print "I will now count my chickens:"
print "Hens", 25 + 30 / 6
print "Roosters", 100 - 25 * 3 % 4
print "Now I will count the eggs:"
print 3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6
print "Is it true that 3 + 2 < 5 - 7?"
print 3 + 2 < 5 - 7
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
|
$ 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
$