Python系列之笨方法学Python是我学习《笨方法学Python》—Zed A. Show著

的学习思路和理解,如有不如之处,望指出!!!

本节我们利用前面学过的ifelseelif语言知识,做一个小游戏,比较简单,很好理解

[TOC]

源代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# ex31.py

print
you enter a dark room with two doors.Do you go through door #1 or door #2?
"""
door=raw_input("> "
if
print
print
print

bear=raw_input("> "
if
print
elif
print
else
print
elif
print
print
print
print

insanity=raw_input("> "
if
print
else
print
else
print

需要注意的几点:

  1. if语句必须以else语句结尾,中间elif语句的数量没有限制

  2. if语句、else语句和elif语句中间可以任意插入if语句、else语句和elif语句

你应该看到的结果


这是**《笨方法学Python》**的第十六篇文章

希望自己可以坚持下去

希望你也可以坚持下去