摘要: while用起来不如for安全。i = 0numbers = []while i < 6: print "At the top i is %d" % i numbers.append(i) i = i + 1 print "Numbers now: ", numbers print "At ... 阅读全文
posted @ 2014-10-25 11:06 林中细雨 阅读(127) 评论(0) 推荐(0) 编辑
摘要: the_count = [1, 2, 3, 4, 5]fruits = ['apples', 'oranges', 'pears', 'apricots']change = [1, 'pennies', 2, 'dimes', 3, 'quarters']# this first kind of f... 阅读全文
posted @ 2014-10-25 10:47 林中细雨 阅读(182) 评论(0) 推荐(0) 编辑
摘要: # -*- coding: utf-8 -*-"""Created on Fri Oct 24 19:32:45 2014@author: dell"""# -*- coding: utf-8 -*-"""Created on Fri Oct 17 09:14:25 2014generate fig... 阅读全文
posted @ 2014-10-24 19:46 林中细雨 阅读(320) 评论(0) 推荐(0) 编辑
摘要: print "You enter a dark room with two doors. Do you go through door #1 or door #2?"door = raw_input("> ")if door == "1": print "There's a giant bear ... 阅读全文
posted @ 2014-10-24 16:08 林中细雨 阅读(162) 评论(0) 推荐(0) 编辑
摘要: if __name__ == '__main__': a = 100 if a > 90: print "90" elif a > 80: print '80' elif a > 70... 阅读全文
posted @ 2014-10-24 15:55 林中细雨 阅读(126) 评论(0) 推荐(0) 编辑
摘要: people = 20cats = 30dogs = 15if people cats: print "Not many cats! The world is saved!"if people dogs: print "The world is dry!"dogs += 5if people... 阅读全文
posted @ 2014-10-24 15:48 林中细雨 阅读(157) 评论(0) 推荐(0) 编辑
摘要: def break_words(stuff): """This function will break up words for us.""" words = stuff.split(' ') return wordsdef sort_words(words): """Sorts t... 阅读全文
posted @ 2014-10-24 15:20 林中细雨 阅读(125) 评论(0) 推荐(0) 编辑
摘要: print "Let's practice everything." print 'You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs.'poem = """\tThe lovely worldwith... 阅读全文
posted @ 2014-10-24 15:06 林中细雨 阅读(212) 评论(0) 推荐(0) 编辑
摘要: In cases like this, where the independent variable does not have an intrinsic ordering, it isoften a good idea to sort entries by the dependent variab... 阅读全文
posted @ 2014-10-24 11:11 林中细雨 阅读(258) 评论(0) 推荐(0) 编辑
摘要: def add(a, b):print "ADDING %d + %d" % (a, b)return a + bdef subtract(a, b):print "SUBTRACTING %d - %d" % (a, b) return a - bdef multiply(a, b): ... 阅读全文
posted @ 2014-10-24 09:57 林中细雨 阅读(195) 评论(0) 推荐(0) 编辑