原创 笨方法學習Python-習題29: 如果(if)
# coding=utf-8 people = 20 cats = 30 dogs = 15 if people < cats: print("Too many cats! The world is doomed!") i
原创 笨方法學習Python-習題28: 布爾表達式練習
目的:熟練與掌握邏輯表達式 在Python交互頁面輸入以下邏輯語句,確認寫的答案是否正確: True and True # True False and False # False 1 == 1 and 2 == 1 # False
原创 笨方法學習Python-習題30: Else 和 If
# coding=utf-8 people = 30 cars = 40 buses = 15 if cars > people: print("We should take the cars.") elif cars <
原创 笨方法學習Python-習題24: 更多練習
# coding=utf-8 print("Let's practice everything.") print("You\'d need to know \'bout escapes with \\ that do \n newlin
原创 笨方法學習Python-習題22:到現在你學到了哪些東西?
整理了一下,自己學到的內容,大家可以參考: Python3中文編碼 #coding=utf-8 “=”兩邊不要空格 Python3註釋 “#” 一句話 “ """ """ ” 一段話 Python3轉義符 “\”
原创 笨方法學習Python-習題25: 更多更多的練習
目的:寫程序,逐行研究,弄懂它。 定義函數 # coding=utf-8 def break_words(stuff): """This function will break up words for us."""
原创 笨方法學習Python-習題16: 讀寫文件
# coding=utf-8 from sys import argv script,filename = argv print("We're going to erase %r." % filename) print("If yo
原创 笨方法學習Python-習題21: 函數可以返回東西
# coding=utf-8 def add(a,b): print("ADDING %d+%d" %(a,b)) return a + b def subtract(a,b): print("SUBTRACT
原创 笨方法學習Python-習題23: 讀代碼
閱讀更多的Python代碼 貼個鏈接,是本書作者寫的。 https://github.com/zedshaw/lamson/blob/master/lamson/commands.py 本節課涉及的知識 一些可以查到到高質量源代碼的
原创 笨方法學習Python-習題31: 作出決定
# coding=utf-8 # 你進入一個小黑屋,屋內有兩扇門,你選擇進入1還是2? print("You enter a dark room with two doors. Do you go through door #1 or
原创 笨方法學習Python-習題26: 恭喜你,現在可以考試了!
從開始學習到現在已經過半了,後面會繼續學習到邏輯,並通過條件判斷實現有用的功能。 這節練習,就是自己單獨做一道試題。“修改腳本代碼” 原腳本地址:http://learnpythonthehardway.org/exercise26.t
原创 笨方法學習Python-習題27: 記住邏輯關係
在Python中,我們會用到下面的術語來定義事物的真(TRUE)或假(FALSE) 邏輯術語 and 與 or 或 not 非 != (not equal) 不等於 == (equal) 等於 >= (greater-than-equa
原创 笨方法學習Python-習題17: 更多文件操作
# coding=utf-8 from sys import argv # exists將文件名字符串作爲參數,如果文件存在返回True否則False from os.path import exists script,from_fi
原创 笨方法學習Python-習題19: 函數和變量
# coding=utf-8 def cheese_and_crackers(cheese_count,boxes_of_crackers): print("You have %d cheeses!" % cheese_coun
原创 笨方法學習Python-習題34: 訪問列表的元素
如何獲取列表元素: 列表的每一個元素都有一個地址,改地址稱爲“索引(index)”,索引是以“0”開頭,這類數字被稱爲“基數”,意味着你可以抓取任意元素。 我們日常使用的計數,是從1開始的,而編程語言的計數,是從0開始的。也就是說,列表