没事做了个猜数字的游戏:
#! /usr/bin/env python#coding=utf-8 import random #导入python的随机数的包 def guss(): Flag = True #循环标记 gussednum = random.randint(1,100)#生成1到100的随机数 while Flag is True: try: num = int(raw_input("Please entry you number:")) if num < gussednum: #比较输入的数字与生产的随机数大小等并给出提示 print "You number is letter" elif num > gussednum: print "You number is large" elif num == gussednum: print "You are great" Flag = False#如果猜对了就退出 except : print "you number is error" #出入不是数字就报错 if __name__ == "__main__": guss()
时间: 2024-10-14 10:41:43