玩转python(一):一个简单的猜数游戏

目录

前言:

一、程序展示

        二、 程序解析


前言:

前几天刚自学完python,于是抽了点时间准备写一两个程序练一练手,于是就根据网上的一些案例写一个简单的猜数游戏。

一、程序展示

import random
print("------gusee number game-------")
answer=random.randint(1, 100)
choices=input("Please input how many times do you want to guess:")
times=int(choices)
temp=input("Please input the number you think :")
guess=int(temp)
while (guess !=answer and times!=0):
    times=times-1
    if guess<answer:
        print("bother ,you answer is less than the right answer")
    elif guess>answer:
        print("bother,you answer is bigger than the right answer")
    if times>0:
        temp=input("Please again input the number you think :")
        guess=int(temp)
if times==0:
    print("Sorry my bother,you maybe not to be win")
    print("the right answer is ")
    print(answer)
else:
    print("my bother,you are right")
    print("You 're the best")

print("THE GAME IS END")
    

二、 程序解析

random:函数库

random.randint(",")生成范围内的随机数

while 循环语句的调用

if else 和if elif 判断语句的使用

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

靳小锅er

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值