下面是练习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("> ") if door == "":
print("There's a giant bear here eating a cheese cake. What do you do?")
print("1. Take the cake.")
print("2. Scream at the bear.") bear = input("> ") if bear == "":
print("The bear eats your face off. Good job!")
elif bear == "":
print("The bear eats your legs off. Good job!")
else:
print("Well, doing %s is probably better. Bear runs away." %bear) elif door == "":
print("You stare into the endless abyss at Cthulhu's retina.")
print("1. Blueberries.")
print("2. Yellow jacket clothespins.")
print("3. Understanding revolvers yelling melodies.") insanity = input("> ") if insanity == "" or insanity == "":
print("Your body survives powered by a mind of jello. Good job!")
else:
print("The insanity rots your eyes into a pool of muck. Good job!") else:
print("You stumble around and fall on a knife and die. Good job!")
 #ex32.py
1 the_count = [1, 2, 3, 4, 5]
fruits = ['apples', 'oranges', 'pears', 'apricots']
change = [1, 'pennies', 2, 'dimes', 3, 'quarters'] # this first kind of for-loop goes through a list
for number in the_count:
print("This is count %d" % number) # same as above
for fruit in fruits:
print("A ftuit of type: %s" % fruit) # also we can go through mixed lists too
# notice we have to use %r since we don't know what's in it
for i in change:
print("I got %r" % i) # we can also build lists, first start with an empty one
#elements = [] elements = range(0, 6)
# then use the range function to do 0 to 5 counts
#for i in range(0, 6):
# print("Adding %d to the list." % i)
# append is a function that lists understand
# elements.append(i) # now we can print them out too
for i in elements:
print("Element was: %d" % i)
 #ex33.py
1 i = 0
numbers = [] while i < 6:
print("At the top i is %d" % i)
numbers.append(i) i = i + 1
print("Numbers now: ", numbers)
print("At the bottom i is %d" % i) print("The numbers: ") for num in numbers:
print(num)
 #ex33+.py
1 # 加分习题
#函数里边的变量和脚本里边的变量之间是没有连接的
#所以定义函数必须返回numbers变量并重新给numbers赋值
def numbers_append(j,k):
i = 0
numbers = []
while i < j:
print("At the top i is %d" % i)
numbers.append(i) i = i + k
print("Numbers now: ", numbers)
print("At the bottom i is %d" % i)
return numbers numbers = numbers_append(6, 1) print("The numbers: ") for num in numbers:
print(num)
#ex34.py
1 animals = ['bear', 'tiger', 'penguin', 'zebra']
bear = animals[1]
print(bear)
 #ex35.py
1 #sys.exit() 引发一个 SystemExit异常,若没有捕获这个异常,Python解释器会直接退出;捕获这个异常可以做一些额外的清理工作。0为正常退出,其他数值(1-127)为不正常,可抛异常事件供捕获。
from sys import exit def gold_room():
print("This room is full of gold. How much do you take?") next = input("> ")
if "" in next or "" in next:
how_much = int(next)
else:
dead("Man, learn to type a number.") if how_much < 50:
print("Nice, you're not greedy, you win!")
exit(0)
else:
dead("You greedy bastard!") def bear_room():
print("There is a bear here.")
print("The bear has a bunch of honey.")
print("The fat bear is in front of another door.")
print("How are you going to move the bear?")
bear_moved = False
while True:
next = input("> ") if next == "take honey":
dead("The bear looks at you then slaps your face off.") elif next == "taunt bear" and not bear_moved:
print("The bear has moved from the door. You can go through it now.")
bear_moved = True elif next == "taunt bear" and bear_moved:
dead("The bear gets pissed off and chews your leg off.") elif next == "open door" and bear_moved:
gold_room() else:
print("I got no idea what that means.") def cthulhu_room():
print("Here you see the great evil Cthulhu.")
print("He, it, whatever stares at you and you go insane.")
print("Do you flee for your life or eat your head?") next = input("> ") if "flee" in next:
start()
elif "head" in next:
dead("Well that was tasty!")
else:
cthulhu_room() def dead(why):
print(why, "Good job!")
exit(0) def start():
print("You are in a dark room.")
print("There is a door to your right and left.")
print("Which one do you take?") next = input("> ") if next == "left":
bear_room()
elif next == "right":
cthulhu_room()
else:
dead("You stumble around the room until you starve.") start()

笨办法学Python(learn python the hard way)--练习程序31-35的更多相关文章

  1. 笨办法学 Python (Learn Python The Hard Way)

    最近在看:笨办法学 Python (Learn Python The Hard Way) Contents: 译者前言 前言:笨办法更简单 习题 0: 准备工作 习题 1: 第一个程序 习题 2: 注 ...

  2. [IT学习]Learn Python the Hard Way (Using Python 3)笨办法学Python3版本

    黑客余弦先生在知道创宇的知道创宇研发技能表v3.1中提到了入门Python的一本好书<Learn Python the Hard Way(英文版链接)>.其中的代码全部是2.7版本. 如果 ...

  3. 笨办法学 Python (第三版)(转载)

    笨办法学 Python (第三版) 原文地址:http://blog.sina.com.cn/s/blog_72b8298001019xg8.html   摘自https://learn-python ...

  4. 笨办法学Python - 习题1: A Good First Program

    在windows上安装完Python环境后,开始按照<笨办法学Python>书上介绍的章节进行练习. 习题 1: 第一个程序 第一天主要是介绍了Python中输出函数print的使用方法, ...

  5. 笨办法学python 13题:pycharm 运行

    笨办法学python 13题 代码: # -*- coding: utf-8 -*- from sys import argv # argv--argument variable 参数变量 scrip ...

  6. 笨办法学python - 专业程序员的养成完整版PDF免费下载_百度云盘

    笨办法学python - 专业程序员的养成完整版PDF免费下载_百度云盘 提取码:xaln  怎样阅读本书 由于本书结构独特,你必须在学习时遵守几条规则 录入所有代码,禁止复制粘贴 一字不差地录入代码 ...

  7. 笨办法学Python 3|百度网盘免费下载|新手基础入门书籍

    点击下方即可百度网盘免费提取 百度网盘免费下载:笨办法学Python 3 提取码:to27 内容简介: 本书是一本Python入门书,适合对计算机了解不多,没有学过编程,但对编程感兴趣的读者学习使用. ...

  8. 《笨办法学 Python(第四版)》高清PDF|百度网盘免费下载|Python编程

    <笨办法学 Python(第四版)>高清PDF|百度网盘免费下载|Python编程 提取码:jcl8 笨办法学 Python是Zed Shaw 编写的一本Python入门书籍.适合对计算机 ...

  9. 笨办法学python 第四版 中文pdf高清版|网盘下载内附提取码

    笨办法学 Python是Zed Shaw 编写的一本Python入门书籍.适合对计算机了解不多,没有学过编程,但对编程感兴趣的朋友学习使用.这本书以习题的方式引导读者一步一步学习编 程,从简单的打印一 ...

  10. 《笨办法学Python 3》python入门书籍推荐|附下载方式

    <笨办法学Python 3>python入门书籍免费下载 内容简介 本书是一本Python入门书,适合对计算机了解不多,没有学过编程,但对编程感兴趣的读者学习使用.这本书以习题的方式引导读 ...

随机推荐

  1. 每日js练习

    第一次玩codewars,选了个最简单的题目 要求是: You have to write a function that describe Leo: if oscar was (integer) 8 ...

  2. Haystack Python全文检索框架

    Haystack 1.什么是Haystack Haystack是django的开源全文搜索框架(全文检索不同于特定字段的模糊查询,使用全文检索的效率更高 ),该框架支持Solr,Elasticsear ...

  3. java学习day3运算符

    一.算数运算符 1.对于除号“/”,它的整数除和小数除是有区别的:当整数除以整数的时候,会把结果的小数部分舍弃,只保留整数部分,例如: int x=3510; x=x/1000; 输出结果为x=3; ...

  4. 初学css list-style属性

    网上很多css布局中会看到这样的一句:list-style:none: 那么list-style到底什么意思?中文即:列表样式:无: 其实它是一个简写属性,包含了所有列表属性,具体包含list-sty ...

  5. SQL 常用语句(一)

    --SQL 语句为表添加字段并设置默认值 alter table TableName add ColumnName int --字段类型 not null --是否为空 --默认值 --SQL 语句为 ...

  6. ISC2016训练赛 phrackCTF--Classical CrackMe

    测试文件:https://static2.ichunqiu.com/icq/resources/fileupload/phrackCTF/REVERSE/CrackMe.rar 1.准备 获得信息 3 ...

  7. Win10系统下插入耳机前面板无声后面板有声的处理

    问题描述: 当耳机插入后面板绿色口(注意:耳机扬声器为绿色口,红色为话筒麦克风:前后面板一样):可以听到声音,但是转到前面板插入后,无声音:调出声音面板发现声音可随音度波动 处理步骤: 1.保证插牢接 ...

  8. ASE Alpha Sprint - backend scrum 9

    本次scrum于2019.11.14再sky garden进行,持续15分钟. 参与人: Xin Kang, Zhikai Chen, Jia Ning, Hao Wang 请假: Lihao Ran ...

  9. .NET Reactor使用教程(加密源代码示例)

    更多:https://www.cnblogs.com/PiaoMiaoGongZi/category/1120300.html 1.打开 Eziriz .NET Reactor,主界面如图1所示: 图 ...

  10. 05.Linux-CentOS系统本地Yum源搭建

    CentOS系统 1.挂载镜像光盘[root@localhost ~]# mount /dev/sr0 /media/cdrom/ 2.创建本地yum源仓库[root@localhost ~]# cd ...