栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

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

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

玩转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 guessanswer:
        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 判断语句的使用

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/286122.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号