码迷,mamicode.com
首页 > 编程语言 > 详细

python 初学--第一个猜数字小游戏

时间:2014-12-26 18:31:18      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:

import random
num = random.randint(0,100)
print num
times = 0

print "Number[0,100] guess game"
print "You will have 10 times to guess"
print "Guess out of range will game over immediately!"

guess = int(raw_input("guess a number:"))
times = times + 1

while times < 10:
    if guess<0 or guess>100:
        print "Your guess is out of range!Game over!"
        breakelse:
        if guess > num:
            print "Too high,guess again!"
        elif guess < num:
            print "Too Low,guess again!"
        else:
            print "You guess it.The number is:",num
            score = 10*(11-times)
            print "times is:",times
            print "Your score is",score
            break
        guess = int(raw_input("guess a number:"))
        times = times + 1
else:
    if guess > num:
        print "Too high,The number is:!",num
        print "Guess times over,game over!"
    elif guess < num:
        print "Too Low,The number is:!",num
        print "Guess times over,game over!"
    else:
        print "You guess it.The number is:",num
        score = 10*(11-times)
        print "times is:",times
        print "Your score is",score

 

python 初学--第一个猜数字小游戏

标签:

原文地址:http://www.cnblogs.com/leoblog/p/4187146.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!