game——Guess the number!
来源:互联网 发布:监守自盗 知乎 编辑:程序博客网 时间:2024/05/21 22:45
最近尝试利用《父与子编程》学习一下Python语言,但是发现书中用的是Python2.7,但是我安装的是python3.60,而两个版本的的程序语言以及函数格式有较大的差别,作为一个初学者费了一点点的功夫对书中的程序练习进行了3-2版本的转变。
import randomsecret=random.randint(1,99)guess=0tries=0print ("AHOY! I'm the Dread Pirate Roberts,and I have a secret!")print("It's a number from 1 to 99. I'll give you 6 tries.")while guess!=secret and tries<6: guess=int(input("what's your guess?")) if guess<secret: print("Too small! Try a larger one!") elif (guess>secret): print("Too large, landlubber!") tries=tries+1if guess==secret: print("Avast! You get it!")else: print("No more guesses! Better luck next time,matey!") print("The secret number is", secret)
主要进行的改变有:print在Python2版本中不是作为函数出现的,可以直接用print“XXXXX”来进行输出;而在python3版本中,print作为函数需要进行print("XXXXX")的变化。
另外需注意while以及if、elif的缩进大小,相同的逻辑层次,缩进数需相同。
阅读全文
0 0
- game——Guess the number!
- Mini-project # 2 - "Guess the number" game"
- Guess Number Game
- lintcode:Guess Number Game
- Interactive Python:Mini-project # 1 - "Guess the number" game"
- 1562 Guess the number
- Guess the Number
- HDOJ1562 Guess the number
- lintcode(662)Guess Number Game
- lintcode Guess Number Game(Java)
- LintCode Guess Number Game II
- lintcode Guess Number Game II
- EOJ 1095 Guess the Number
- hdu 1562 Guess the number
- hdu 1562 Guess the number
- hdoj-1562-Guess the number
- HDU 1562 Guess the number
- HDU 1562 Guess the number
- Qt Widgets、QML、Qt Quick的区别
- segmentation fault (core dumped)调试
- 20:反反复复
- 国庆来个maven父子项目创建
- mongo3.x yarn配置
- game——Guess the number!
- 第一次使用construct的感受
- C语言排序函数qsort( )
- Dash Speed
- linux下用户理解
- Cocos2D-x游戏开发之:CCNotificationCenter观察者模式基础
- [未完待续][笔记]数论相关---基础
- 自己模拟实现strcat函数的功能
- 排序详解:堆排序