learn python the hard way
helixprocess
这个作者很懒,什么都没留下…
展开
-
learning python te15
from sys import argvscript,filename = argvtxt = open(filename)print "here's your file: %r" %filenameprint txt.read()print "type the filename again:"file_again = raw_input(">")txt_again = o原创 2018-01-30 20:30:29 · 113 阅读 · 0 评论 -
te30
people = 30 cars = 40buses = 15if cars > people : print"we should take the cars."elif cars <people: print"we should not take the cars."else: print "we can't decide." if buses > ca...原创 2018-02-27 21:34:30 · 104 阅读 · 0 评论 -
te31
#coding=utf-8 #if function have two level.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 he...原创 2018-02-28 10:45:23 · 123 阅读 · 0 评论 -
te32
the_count = [1,2,3,4,5]fruits = ['apples','oranges','pears','apricots']change = [1,'pennies',2,'dimes',3,'quarters']#this first kinf of for-loop goes through a listfor number in the_count: print...原创 2018-02-28 11:12:17 · 137 阅读 · 0 评论 -
te41
from sys import exitfrom random import randint #aimed to create random numberdef death(): '''you will die with a random words''' die = ["you died.you kinda suck at this.","nice job, you died .....原创 2018-03-08 13:35:19 · 188 阅读 · 0 评论 -
te42
# -*-coding:utf-8-*- class TheThing(object): def __init__(self): self.number = 0#初始化 .number是self的一个属性 self就是自己 def some_function(self): print"i got called."#类下面的函数 打印xxxxx def add_m...原创 2018-03-08 15:07:18 · 331 阅读 · 1 评论 -
te33
def add_number(n,numbers ): i = 0 while i < n: print"at the top i is %d"%i numbers.append(i) i = i+1 print "numbers now:",numbers print"at thr bottom i is %d"%inumbers = []add_numbe...原创 2018-03-01 12:54:40 · 298 阅读 · 0 评论 -
te35
from sys import exitdef gold_room(): print"this room is full of gold.how much do you take?" next = raw_input(">") if "0" in next or "1" in next: how_much = int(next) else: dead("man,lea...原创 2018-03-01 14:04:19 · 182 阅读 · 0 评论 -
te36 初学建议
if语句规则:每一个if都应该包含一个else如果这个else永远不应该被执行,因为本身没有意义,就在else后面加一个die函数让他死掉if语句嵌套不要超过俩层,最好尽量一层,如果有嵌套的if可以移动到另外的函数中if语句的moudle应该前后各空一行以示区分布尔测试应该很简单否则就命名一个变量循环:只有要永不停止是用while循环最好用for循环,尤其数量固定,若要判断可以range(0,a)...原创 2018-03-02 12:30:28 · 229 阅读 · 0 评论 -
te18
#this one is like your scripts with argvdef print_two(*args): arg1,arg2 = args print "arg1:%r, arg2 :%r"%(arg1,arg2) #ok, tha *args is actually pointless ,wecan just do thisdef print_two_again(a...原创 2018-02-24 16:38:30 · 706 阅读 · 0 评论 -
te19
def cheese_and_crackers(cheese_count,boxes_of_crackers): print "you have %d cheeses!"% cheese_count print "you have %d boxes of crsckers!" %boxes_of_crackers print "man that's enough for a party!"...原创 2018-02-24 19:08:30 · 142 阅读 · 0 评论 -
te19-plus 写一个函数用十种方法运行
def max(num1,num2): if num1>=num2: return num1 else : return num2 max(10,20)#1print"max:%r" %maxint a= input(a)#2int b= input(b)max(a,b)print"max:%r" %maxfrom sys import argv #3...原创 2018-02-24 19:10:13 · 215 阅读 · 0 评论 -
te20
from sys import argvscript,input_file = argvdef print_all(f): print (f.read()) def rewind(f): f.seek(0) def print_a_line(line_count,f): print (line_count,f.readline()) current_file = open(...原创 2018-02-24 20:59:27 · 170 阅读 · 0 评论 -
te29
#coding=utf-8 people = 20cats = 30dogs = 15if people < cats : print"too many cats! the world is doomed!" if people > cats : print"not many cats! the world is saved." if people < d...原创 2018-02-27 21:32:47 · 94 阅读 · 0 评论 -
te26 修改任务
def break_words(stuff): """This function will break up words for us.""" words = stuff.split(' ') return wordsdef sort_words(words): """Sorts the words.""" return sorted(words原创 2018-02-27 21:30:10 · 511 阅读 · 0 评论 -
learning python te16
from sys import argvscript, filename = argvprint "we're going to erase %r."%filenameprint "if you don't want that, hit CTRL-C."print "if you want that, hit RETURN."raw_input("?")print "open原创 2018-01-30 21:08:43 · 129 阅读 · 0 评论 -
learn python te10
tabby_cat = "\ti'm tabbed in."persian_cat = "i'm split\non a line"backslash_cat = "i'm \\ a \\ cat."fat_cat = '''i'll do a list:\t* cat food\t* fishies\t* catnip \n\t* grass'''print tabby_c原创 2018-01-28 21:51:04 · 121 阅读 · 0 评论 -
learn python te11
print "how old are you?",age = raw_input ()print "how tall are you?",height = raw_input()print "how much do you weight?",weight =raw_input()print "so,you're %r old, %r tall and %r heavy." %(age原创 2018-01-28 22:18:16 · 260 阅读 · 0 评论 -
learning python te12
age = raw_input("how old are you")height = raw_input("how tall are you")weight = raw_input("how much do you weight")print "so, you're %r old, %r tall and %r heavy." %(age, height, weight)raw_i原创 2018-01-29 20:46:04 · 109 阅读 · 0 评论 -
learn python te9
days = "mon tue wed thu fri sat sun"months = "jan \n feb \n mar \n apr \n may \n jun \n jul \n aug"print "here are the days:",daysprint "here are the months:",monthsprint """there's something原创 2018-01-28 21:53:40 · 127 阅读 · 0 评论 -
learning pthon te13
from sys import argvscript,first,second,third = argvprint "the script is called:",scriptprint "your first variable is:",firstprint "your second varible is:", secondprint "your third variable is原创 2018-01-29 21:26:31 · 101 阅读 · 0 评论 -
learning python te14
from sys import argvscript, user_name = argvprompt = '>'print "hi %s, i'm the %s script." %(user_name,script)print "i'd like to ask you a few questions."print "do you like me %s?" %user_nameli原创 2018-01-29 21:45:17 · 138 阅读 · 0 评论 -
te24
print "let's practice everything"print'you\'d need to know \'bout escapes with \\ taht do \nnewlines and \t tabs'poem = """\tthe lovely worldwith logic so firmly plantedcannot discern \n the nee...原创 2018-02-26 22:01:45 · 116 阅读 · 0 评论 -
te25
def break_words(stuff): '''this function will brerak up words for us.''' words = stuff.split(' ') return words def sort_words(words): '''sorts the words.''' return sorted(words) def print_f...原创 2018-02-26 22:03:55 · 144 阅读 · 0 评论 -
te39
ten_things = 'apples oranges crpws telephone light sugar'print 'wait there\'s not ten things in the list, let\' fix it.'stuff = ten_things.split(' ')more_stuff = ['day','night', 'song', 'feisee',...原创 2018-03-07 12:21:45 · 124 阅读 · 0 评论 -
te40
cities = {'CA':'san fransico', 'MI':'detroit','FL':'jacksonville'}cities['NY'] = 'new york'cities['OR'] = 'portland'def find_city(themap, state): if state in themap: return themap[state] else:...原创 2018-03-07 13:07:46 · 204 阅读 · 0 评论 -
对python符号的理解
Keywords• and 逻辑算符 和• del 删除后面的变量• from • not 相反 • while while循环 • as • elif elseif• global 定义为全局变量• or 逻辑算符 或 • with • assert • else 其他• if ...原创 2018-03-04 14:22:09 · 505 阅读 · 0 评论