依然少打很多剧情,并修改了很多,还好,能运行 #!urs/bin/python #coding:utf-8 from sys import exit from random import randint class Game(object): def __init__(self,start): self.quips = [ "you died.", "such a luser.",] self.start = start def play(self): next =…
最近在看:笨办法学 Python (Learn Python The Hard Way) Contents: 译者前言 前言:笨办法更简单 习题 0: 准备工作 习题 1: 第一个程序 习题 2: 注释和井号 习题 3: 数字和数学计算 习题 4: 变量(variable)和命名 习题 5: 更多的变量和打印 习题 6: 字符串(string)和文本 习题 7: 更多打印 习题 8: 打印,打印 习题 9: 打印,打印,打印 习题 10: 那是什么? 习题 11: 提问 习题 12: 提示别人…
黑客余弦先生在知道创宇的知道创宇研发技能表v3.1中提到了入门Python的一本好书<Learn Python the Hard Way(英文版链接)>.其中的代码全部是2.7版本. 如果你觉得英文版看着累,当当网有中文版,也有电子版可以选择. 我试着将其中的代码更新到Python 3.同时附上一些自己的初学体会,希望会对你有帮助. 中文版有人把书名翻译为<笨办法学python>,其实我觉得叫做<学Python,不走寻常路>更有意思些. 作者的意思你可以在序言中详细了解…
学 Python (Learn Python The Hard Way) Contents: 译者前言 前言:笨办法更简单 习题 0: 准备工作 习题 1: 第一个程序 习题 2: 注释和井号 习题 3: 数字和数学计算 习题 4: 变量(variable)和命名 习题 5: 更多的变量和打印 习题 6: 字符串(string)和文本 习题 7: 更多打印 习题 8: 打印,打印 习题 9: 打印,打印,打印 习题 10: 那是什么? 习题 11: 提问 习题 12: 提示别人 习题 13: 参…
这几天有点时间,想学点Python基础,今天看到了<learn python the hard way>的 Ex48,这篇文章主要记录一些工具的安装,以及scan 函数的实现. 首先与Ex48相关的章节有前面的Ex46, Ex47,故我们需要先安装一些工具,主要是一些包管理和测试框架的软件: Install the following Python packages: pip from http://pypi.python.org/pypi/pip distribute from http:/…
This tutorial is available as a short ebook. The e-book features extra content from follow-up posts on various Python best practices, all in a convenient, self-contained format. All future updates are free for people who purchase it. Preliminary fluf…
1. How to run the python file? python ...py 2. UTF-8 is a character encoding, just like ASCII. 3. round(floating-point number) 4. %r print the way you write. It prints whatever you write, even if you have special characters, such as '\n'. 5. how to o…
下面是练习42,基于python3 #ex42.py 1 class TheThing(object): 2 #__init__为class设置内部变量的方式,正常情况下函数内的变量与外部没有关联,但是这里的number变量却可以在class下关联 3 def __init__(self): 4 self.number = 5 5 6 def some_function(self): 7 print("I got called.") 8 9 def add_me_up(self, mo…
我承认,我偷懒了,少打了大量代码(剧情),英文太差,下次可以编个中文的试试 #!/urs/bin/python #coding:utf-8 from sys import exit from random import randint def death(): quips=["you died. you kinda suck at this.", "nice job,you died ...jackass.", "such a luser", &…
下面是练习31-练习35,基于python3 #ex31.py 1 print("You enter a dark room witn two doors. Do you go through door #1 or door #2?") door = input("> ") ": print("There's a giant bear here eating a cheese cake. What do you do?") pri…
#!/usr/bin/python #coding:utf-8 from sys import exit def gold_room(): print "this room is full of gold. how much do you take?" next = raw_input(">>") " in next: how_much = int(next) else: dead("man, learn to type a numb…
for notes of learing python. // just ignore the ugly/wrong highlight for python code. """odbchelper.py sample script This program is part of "Dive Into Python", a free Python book for experienced programmers. Visit http://diveinto…
# this will not be printed in python ! print "I could have code like this." # and the comment after is ignored # You can also use a comment to "disable" or comment out a piece of code: # print "This won't run. " print "T…
今天搜索了一下raw_input() 和 input()的区别,引用下原文部分内容 两个函数均能接收 字符串 ,但 raw_input() 直接读取控制台的输入(任何类型的输入它都可以接收).而对于 input() ,它希望能够读取一个合法的 python 表达式,即你输入字符串的时候必须使用引号将它括起来,否则它会引发一个 SyntaxError . raw_input() 将所有输入作为字符串看待,返回字符串类型.而 input() 在对待纯数字输入时具有自己的特性,它返回所输入的数字的类型…
0, 看了一个python项目开源源码, 才知道现在这点python知识实在是弱爆了.. 尼玛就像学了2500个常用汉字, 然后要去理解"楚辞".. 代码如下, 解释一点一点从网上查, 随后: ############################################################################### class BaseEstimator(object): """Base class for all es…
Python 中的列表: 形式:[ 表示打开一个列表,中间的项目用 , 隔开,然后列表以 ] 结束. for循环 两种形式: for i in ArrayName: for i in range(0,6): 其中的变量 i 在使用 for 循环的时候, Python 自动创建,作为进行循环的索引.第一种形式中,遍历列表中的每一个元素.第二种形式中,range(0,6), 从 0 开始,到 6 前结束,不包括6. 列表包含的函数:append 字典 列表是将一些键对应一些值的数据结构,这样就不需要…
定义函数和调用函数的语法 定义函数 形式: def functionName(p1,p2): statement other statement 需要注意: 紧跟者函数定义的代码是否使用了4个空格的缩进?不能多,也不能少 函数结束的位置是否取消了缩进? 调用函数 形式:functionname(a1,a2) UTF-8的相关知识 UTF-8 是 Unicode Transformation Format 8 Bits 的简称,是一种编码规定,其目的在于减少编码时候的文本对内存的浪费.这是一种压缩…
习题6总结 定义字符串: 名字 = 值 其他 你也可以用 {types_of_people}的方式把它放在任何字符串中. 也就是说你可以在其他字符串中添加{},然后前面加一个 f,可用print()进行直接打印. f-string 特殊的字符串类型:f-string举例:f" some stuff have {avariable}" .format()格式化方式: python 还有一种 使用 .format()语法的格式化方式:.format()格式化方式: joke_evaluat…
习题1 print 语句print('Yay! Printing.')print('I "said" do not touch this') 习题2:注释和 # 号 #(octothorpe),用于注释一条语句,在 # 之后的内容全部被忽略. 习题3:数字和数字计算 当进行关系运算的时候,比如 3+2<5-7,那么返回的是一个 True 或者 False 习题4:变量和命名 设定变量之后,可以在以后的时候用到. 习题5:更多的变量和打印 print(f"{}"…
print "Hello World!" action = raw_input("please select your action{1, 2, 3, 4, 5, 6, 7, 8, 9, o}: ") print action if action == str("1"): #print hello name name = raw_input("what's your name? ") print "Hello &qu…
ex46中,创建自己的python,  当你激活环境时 .\.venvs\lpthw\ Scripts\activate 会报一个错误 此时需要以管理员身份运行PowerShell,(当前的PS不用关,重新开一个PS,方法是开始菜单里搜索PS右键以管理员身份运行) 然后输入命令 set-executionpolicy remotesigned 选择Y.现在再回到刚才的PS窗口, 应该可以了…
############################################################################### codecademy python 5.5# Define a function factorial that takes an integer x as input.# Calculate and return the factorial of that number.# def digit_sum(x):# mul = 1# for…
下面是练习41,基于python3 #ex41.py 1 #打印文档字符串 print(函数名.__doc__) 2 from sys import exit 3 from random import randint 4 5 def death(): 6 quips = ["You died. You kinda suck at this.", 7 "Nice job, you died ...jackass.", 8 "Such a luser.&quo…
#!/usr/bin/python #coding:utf-8 # animal is-a object(yes,sort of sonfusing)look at the extra credit class Animal(objeck): pass #Dog 类 继承 Animal class Dog(Animal): def __init__(self,name): #对 对象Dog赋值 name self.name =name #Cat 类 继承 Animal class Cat(Ani…
下面是当初看这本书时按照书中的代码做的练习,一行一行敲下来的,都已经试运行过,没有错误(基于python3),练习1-练习10 #ex1.py 1 #print("Hello world!") 2 print("Hello again") 3 print("I like typing this.") 4 print("This is fun.") 5 print('Yay!Printing.') 6 print("I…
#!/usr/bin/python #coding:utf-8 cities ={'CA':'sf','MI':'dt','FL':'je'} #创建字典 cities['NY']='ny' #增加新元素 cities['OR']='pd' def find_city(themap,state): if state in themap: return themap[state] else: return 'not found' #ok pay attention cities['_find']…
#!/usr/bin/python #coding:utf-8 ten_things = "apples oranges crows telephone light sugar" print "wait there's not 10 things in that list,let's fix that" stuff = ten_things.split(' ') #10个东西,以' '间隔开 more_stuff = ["day","n…
本练习为复习python的符号和关键字 数据类型有:True False None Strings numbers floats lists dict tuple set """ Data Types True False None Strings numbers floats lists dict tuple set """ dicts = {'1':'apple', '2':"pear", 3:"bear&quo…
本练习为复习python的符号和关键字 关键字有: #and or False True print(1==0 and 2==0, 1==0 or 2==0) print(False) print(True)输出: False FalseFalseTrue lists = ['1', '2', 'a', 'afds', 3, 463] """ del:Deletion of a target list recursively deletes each target, from…
import random from urllib import urlopen import sys WORD_URL = "http://learncodethehardway.org/words.txt" WORDS = [] PHRASES = { "class %%%(%%%):": "Make a class named %%% that is-a %%%.", "class %%%(object):\n\tdef __in…