我的第一个python小程序

我的第一个python小程序——猜数字游戏
My first Pyhton program——guess the number 

#!/usr/bin/python
# -*- coding: UTF-8 -*-
print("--------小游戏-------")
temp=input("请输入您认为正确的数字:")
i=int(temp)
import random
s=random.randint(0,1000)
sum=0
print(s)
while i!=s:
    sum=sum+1
    if sum<5:
        if i<s:
            print("猜小了!")
            temp=input("请重新输入您认为正确的数字:")
            i=int(temp)
            continue
        elif i>s:
            print("猜大了!")
            temp=input("请重新输入您认为正确的数字:")
            i=int(temp)
            continue
    else:
        print("您的机会用完了!游戏结束!")
        break
if i==s:
    print("猜中了!游戏结束!")
    sum=sum+1
print("您一共猜测了%d次!"%sum)

猜你喜欢

转载自www.cnblogs.com/ooops/p/9211355.html