首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

Learn Python The Hard Way学习(14) - 揭示和传递

2012-06-20 
Learn Python The Hard Way学习(14) - 提示和传递让我们做一个把argv和raw_input结合使用的例子,为下个例

Learn Python The Hard Way学习(14) - 提示和传递
让我们做一个把argv和raw_input结合使用的例子,为下个例子学习读写文件打下基础。在这个例子中,raw_input只给了一个简单的提示,有点像游戏Zork或者Adventure。


我们设置了一个prompt变量,在raw_input中做参数,这样就不用每次都写这个参数了,而且修改的时候修改一个地方就可以了,很方便吧。
运行结果root@he-desktop:~/mystuff# python ex14.py ericHi eric, I'm the ex14.py script.I'd like to ask you a few questions.Do you like me eric?> yesWhere do you live eric?> ChinaWhat kind of computer do you have?> Candy
Alright, so you said 'yes' about liking me.You live in 'China', Not sure where that is.And you have a 'Candy' computer, Nice.
root@he-desktop:~/mystuff# 
加分练习1. 找Zork和Adventure游戏来玩玩。
2. 改变变量prompt,然后重新执行一次。
3. 添加一个其他的参数到程序中。
4. 确认弄懂了"""表示多行输出,%是表示格式化媒介。

热点排行