習題3 數字和數學計算
#!usr/bin/python
#--coding:utf-8--
print
"i will now count my chickens:"
#表示式中只有數**算符,就輸出運算結果,與字串用逗號分隔
print
"hens", 25.0 + 30 / 6
print
"roosters", 100.0 - 25 * 3 % 4
print
"now i will count the eggs:"
print
3.0 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6
#字串內有數**算符和邏輯運算子,均不做任何處理,直接輸出
print
"is it true that 3 + 2 < 5 - 7?"
#字串外的表示式中有邏輯運算子,輸出邏輯運算結果true/false
print
3.0 + 2
< 5.0 - 7
print
"what is 3 + 2?", 3.0 + 2
print
"what is 5 - 7?", 5.0 - 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
執行結果:
my chickens:
hens 30.0
roosters 97.0
now i will count
the eggs:
7.0is it
true
that
3 + 2
< 5 - 7?
false
what is
3 + 2? 5.0
what is
5 - 7? -2.0
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
其他:數**算符號:
+ plus 加法運算
- minus 減法運算
/ slash 取整運算
* asterisk 乘法運算
% percent 取餘運算
邏輯運算符號:
greater-than
less-than
greater-than-equal
less-than-equal
浮點數:
笨方法學Python 習題0
第一天學習,教材是中文第四版,完全零基礎 之前電腦上安裝了anaconda 所以現在是這個狀態,不知道python 3在之後的學習有沒有什麼問題,先這樣再說吧 ctrl z撤銷,回到python之前 windows裡terminal 就是指powershell 建立目錄 mkdir 進入目錄 cd ...
笨方法學python 習題4 5 6 7 8
習題4 space in a car中 car是假想空格字元 附加題 我的3的版本裡只用4沒有問題,我的猜想是2中如果除數都是int,答案會是去掉小數剩下的部分 比如說如果最後答案是3.75,python會顯示3,而實際上我們應該得出4這個答案,就不匹配了。是assignment,equal to ...
《 笨方法學 Python 》 習題 6 9
習題 6 字串和文字 x there are d types of people.10 binary binary do not don t 如果在字串中通過格式化字元放入多個變數,需要將變數放到 中,變數之間用逗號隔開 y those who know s and those who is s.b...