2--一个简单的小游戏

import random
secret = random.randint(1,10)
print('-------------------gclome-------------------')
temp = input("不妨输入我现在心里想的那个数字:")
guess= int(temp)
while guess != secret:
    temp = input("哎呀,猜错了,请重新输入吧:")
    guess= int(temp)
    if guess==secret:
        print("你是我的蛔虫吗哈哈哈哈")
        print("哼,猜中了也没有奖励")
    else:
        if guess > secret:
            print("大了大了")
        else:
            print("小了小了!")
print("游戏结束,不玩啦!")

Python的条件分支语言

1、if else语句
If
Else

2、While循环
While 条件:
条件为真(true)执行的操作

random模块里面有个函数叫做 randint(),会返回一个随机的整数

猜你喜欢

转载自blog.csdn.net/qq_44108455/article/details/107119350