刚学Python时间不长,但也知道了一点,看别人的参考写了一个猜数字小游戏,也算是禹学于乐吧。
#!/usr/bin/env python
#coding=utf-8
import random
secret = random.randint(1,100)
guess,tries = 0,0
print u"已经给出了一个1-99的数字"
while guess != secret and tries < 5:
print u"请给出你猜的数字:"
guess_str = raw_input()
g = int(guess_str)
if g == secret:
print u"waaaaa.....OK, 你猜对了。"
break
elif g < secret:
print str(g),u"you are wrong. 太小了 "
elif g > secret:
print str(g),u"you are wrong. 太大了"
tries += 1
else:
print u"猜了5次都没猜到,智商有点捉急阿!!!"
print u"想知道答案吗?求我呀~~hiahiahia"
print u"好吧,这个数字就是:",str(secret)
本文出自 “11944248” 博客,请务必保留此出处http://11954248.blog.51cto.com/11944248/1963990
原文地址:http://11954248.blog.51cto.com/11944248/1963990