笨辦法學(xué)Python ex03

數(shù)字和數(shù)學(xué)計(jì)算


  • 輸入:
# -- coding: utf-8 --

print "I will now count my chickens:"
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 equla?", 5 <= -2
  • 運(yùn)行:

附加題


  • 浮點(diǎn)數(shù)(floating point number)

<strong>“浮點(diǎn)數(shù)”的定義是相對(duì)于“定點(diǎn)數(shù)”來(lái)說(shuō)的。</strong>
在計(jì)算機(jī)內(nèi)部,數(shù)據(jù)以二進(jìn)制的形式存儲(chǔ)和運(yùn)算,而計(jì)算機(jī)內(nèi)表示的數(shù),又被分成整數(shù)和實(shí)數(shù)兩大類(lèi)。
其中整數(shù)一般用定點(diǎn)數(shù)表示,定點(diǎn)數(shù)指小數(shù)點(diǎn)在數(shù)中有固定的位置(一般來(lái)說(shuō)整數(shù)的小數(shù)點(diǎn)都在最末位數(shù)后)。
實(shí)數(shù)一般用浮點(diǎn)數(shù)表示,因?yàn)樗男?shù)點(diǎn)位置不固定。浮點(diǎn)數(shù)是既有整數(shù)又有小數(shù)的數(shù),純小數(shù)可以看作實(shí)數(shù)的特例。

  • 使用浮點(diǎn)數(shù)重寫(xiě)一遍 ex3.py,讓它的計(jì)算結(jié)果更準(zhǔn)確(提示: 20.0 是一個(gè)浮點(diǎn)數(shù))。
# -- coding: utf-8 --

print "I will now count my chickens:"
print "Roosters", 100.0- 25.0* 3.0 % 4.0

print "Now I will count the eggs:"

print 3.0 + 2.0 + 1.0 - 5.0 + 4.0 % 2.0 - 1.0 / 4.0 + 6.0

print "Is it true that 3.0 + 2.0 < 5.0 - 7.0?"

print 3.0 + 2.0 < 5.0 - 7.0

print "What is 3.0 + 2.0?", 3.0 + 2.0
print "What is 5.0 - 7.0?", 5.0 - 7.0

print "Oh, that's why it's False."

print "How about some more."

print "Is it greater?", 5.0 > -2.0
print "Is it greater or equal?", 5.0 >= -2.0
print "Is it less or equla?", 5.0 <= -2.0
Paste_Image.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容