- # -*- coding: utf-8 -*-
- import math,random
- print "你好啊,小伙子,你叫什么名字"
- name=raw_input()
- print "来玩一个猜数字的游戏吧,猜对有奖哦(1-20,6次机会)"
- class guessnumber(object):
- ans=random.randint(1,20)
- def __init__(self,name):
- self.name=name
- def makeguess(self,guess):
- self.guess=guess
- def makecmp(self):
- if guess<game.ans:
- print "your guess:"+str(guess)+" is smaller than the ans"
- elif guess>game.ans:
- print "your guess:"+str(guess)+" is bigger than the ans"
- else:
- print "congratulations "+name+" you get the right answer"
- game=guessnumber(name)
- make_guess=0
- while make_guess<6:
- guess=input()
- game.makeguess(guess)
- game.makecmp()
- make_guess+=1
- else:
- print "很遗憾,机会用完了游戏结束"
- #该片段来自于http://www.codesnippet.cn/detail/301020136812.html
来源: http://www.codesnippet.cn/detail/301020136812.html