美文网首页
python 猜数字游戏

python 猜数字游戏

作者: 龙小江i | 来源:发表于2018-09-18 20:14 被阅读0次

基础版:

import random
a = random.randint(100,200)
b = input('a: ')
b = int(b)
while b != a:
    b = input('a: ')
    b = int(b)
    if b == a:
        print('yeah')
    else:
        if b > a:
            print('too big')
        else:
            print('too small')
print('game over')

改进版:

import random
a = random.randint(100,200)
b =int(input('a: '))
while b != a:
    if b > a:
        b = int(input('too big, try again: '))
    else:
        b = int(input('too small, try again: '))
print(yeah\ngame over)

相关文章

网友评论

      本文标题:python 猜数字游戏

      本文链接:https://www.haomeiwen.com/subject/qanmnftx.html