设为首页 加入收藏

TOP

2016.8.21猜数游戏
2017-09-30 17:42:09 】 浏览:3884
Tags:2016.8.21 游戏
 1 import random
 2 secret=random.randint(1,99)
 3 guess=0
 4 tries=0
 5 print secret
 6 print"Alex,I have a secret,It is a number from 1 to 99,you have 6 tries."
 7 while guess!=secret and tries<6:
 8     guess=input("Enter you guess number:")
 9     if guess<secret:
10         print " too low"
11     elif guess>secret:
12         print"too hight"
13     tries+=1
14 if guess==secret:
15     print"congratulations"
16 else:
17     print "no more tries"

1.关于tries+=1,在python中,语句块不会单独引进新的作用域,tries还是全局变量,while中改变tries会使tries变量的值改变。

2.逻辑判断。(1)guess!=secret并且tries<6.(2)guess==secret,(3)tries>=6。当(1)不满足时,有(2)(3)两种情况。

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Python 基本语法 学习之路(三) 下一篇Python基础系列----函数,面向对..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目