返回顶部

收藏

Guess My Number

更多
import random  

the_number = random.randrange(100) + 1
guess = int(raw_input('Take a guess: '))
tries = 1

while (guess != the_number):
    if (guess > the_number):
        print 'Lower...'
    else:
        print 'Higher...'

    guess = int(raw_input('Take a guess: '))
    tries += 1

print 'You guessed it!  The number was', the_number
print 'And it only took you', tries, 'tries!\n'

raw_input('\n\nPress the enter key to exit.')

标签:Python,基础

收藏

0人收藏

支持

0

反对

0

»更多 您可能感兴趣的代码
  1. 2012-11-05 21:59:42java获得随机数代码 by 怪兽狂殴奥特曼
  2. 2014-07-28 21:48:26计算未来某个时间点到现在还有多久 by 阿明娃儿
  3. 2014-07-31 14:45:28筛选冒烟用例 by 蟋蟀MM
  4. 2014-08-18 14:05:14Softmax Regression by xwz
  5. 2014-08-26 11:44:11查单词的脚本 by 风云轩
  6. 2014-09-02 13:16:29Python Generators 用法 by 阮小七
  7. 2014-09-14 16:57:09元类 metaclass by jack.chen
  8. 2014-09-19 13:25:44Levenshtein字符串相似度 by xwz
  9. 2014-09-24 15:54:45IP地址与Bigint转换 by 蟋蟀MM
  10. 2014-11-04 15:08:25Python的logging模块封装 by 山药
  11. 2014-11-14 14:28:06Python ConfigParser模块 by xwz

发表评论