玩转python:一个简单的猜数游戏
Posted 靳小锅er
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了玩转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 判断语句的使用
以上是关于玩转python:一个简单的猜数游戏的主要内容,如果未能解决你的问题,请参考以下文章