原创 Learn Python the hard way. 習題30. If和else/elif

#coding=utf-8 age = int(raw_input("Your age?")) if age > 18:  print "your age is", age  print "You are an adult."   eli

原创 Learn python the hard way_習題32_循環和列表

the_count = [1, 3, 5, 6] fruits = ['apple', 'oranges', 'pears', 'apricots'] change = [1, 'pennies', 2, 'dimes', 3, 'qua

原创 while循環,習題33,笨辦法學python

def worker_salary(target_salary, increase_per_month):  initial_salary = 0

原创 函數可以返回某些東西。習題21---learn python the hard way.

#coding=utf-8 def plus(a, b):     return a + b   def jian(a, b):     return a - b   def cheng(a, b):     return a * b  

原创 range()函數。 笨方法學python. 循環和列表。

函數原型:range(start, end, scan): 參數含義:start:計數從start開始。默認是從0開始。例如range(5)等價於range(0, 5);               end:技術到end結束,但不包括en

原创 if 語句----習題29擴展練習。learn python the hard way.

#coding=utf-8 #raw_input()函數輸出的數據是"str",需要將其處理成數據,使用int()函數,將“str"轉換成數據來處理 students = int(raw_input("students number"))

原创 習題30 else 和 if. 附加練習3

#coding=utf-8 #賦值 people = 20 cars = 19 buses =15 if cars > people and buses < cars:  print "Take cars!!!!"   elif car

原创 讀寫文件,python. learn python the hard way

#coding=utf-8 poem = "\t I'm trying to writ this into my file,,ooo" def method_one(): f = open('new.txt', 'w')

原创 try, excep, else, python關鍵詞

python標準異常 異常名稱 描述 BaseException 所有異常的基類 SystemExit 解釋器請求退出 KeyboardInterrupt 用戶中斷執行(通常是輸入^C) Exception 常規

原创 Python, file readline() method

#coding=utf-8 #open a file new = open('new.txt', 'r') print "The name of the file:%s" % new line = new.readline(1)

原创 .realines()應用,將中文文章和對應英文文章,按順序的合併在一起

chinese = open('new2.txt', 'r') english = open('new.txt', 'r') translate = open('translate.txt', 'w') f_chinese =

原创 笨方法學python--習題31---做出決定。

#coding=uft-8 print "You are goonna enroll to our school, what's your age (month)" age = raw_input(">") if age >= "18":

原创 函數與文件-習題20--learn python the hard way

#coding=utf-8 from sys import argv script, file_name = argv def print_all(f):   #函數名     print f.read() #函數代碼,函數的具體操作

原创 Python 函數與變量--習題19,learn python the hard way

#coding=utf-8 def Total_number_of_students(boys, girls):     print "There are %d boys within the environment." % boys  

原创 python,關鍵詞pass

for letter in 'python': if letter == 'h': pass print " This is pass block" print "Current lette