设为首页收藏本站

Crossin的编程教室

 找回密码
 立即加入
楼主: iamocean
打印 上一主题 下一主题

【Python 第8课】while

[复制链接]

0

主题

0

好友

12

积分

新手上路

Rank: 1

71#
发表于 2018-10-17 16:03:52 |只看该作者
a=18
print "猜猜我想的多少"
shuru=int(input())
while shuru<a:
    print "small"
    shuru=int(input())
while shuru>a:
    print "big"
    shuru = int(input())
if shuru==a:
    print "ok"
老师 我这个写法 和你的例子比起来有什么不足的
回复

使用道具 举报

9

主题

2

好友

164

积分

注册会员

Rank: 2

72#
发表于 2021-4-27 17:54:09 |只看该作者
取个名字真难 发表于 2013-9-29 21:37
关于最后的小游戏,我用的是第七课的办法,结果是刷屏输出判断结果:
num = 10
   print 'Guess what I th ...

因为answer = input()只出现了一次,
所以输入数字后,while循环条件始终成立,
就会一直输出。
回复

使用道具 举报

9

主题

2

好友

164

积分

注册会员

Rank: 2

73#
发表于 2021-5-3 19:22:01 |只看该作者
这样也可以:
  1. ......
  2. while True:
  3. ......
  4.     if answer == num:
  5.         print ‘BINGO’
  6.         break
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即加入

QQ|手机版|Archiver|Crossin的编程教室 ( 苏ICP备15063769号  

GMT+8, 2024-4-20 01:22 , Processed in 0.025570 second(s), 23 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部