玩转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")
    

玩转python(一):一个简单的猜数游戏_第1张图片

二、 程序解析

random:函数库

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

while 循环语句的调用

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

你可能感兴趣的:(python,python)