一个简单的猜数字的小游戏,简单猜数字小游戏,[Python]代码#!


[Python]代码

#!/bin/python#coding=gb2312import random;ran=random.randint(1,100);con=True;count=0;while con:    tem=raw_input("请输入一个你认为的数:");    t=True;    while t:        try:            guess=int(tem);            t=False;        except ValueError:            tem=raw_input("请重新输入一个整数:");    if guess==ran:        count=count+1;        con=False;        print "恭喜你,猜中了!你总共猜了%d次!" %count;    elif guess>ran:        count=count+1;        print "你所输入的数偏大!";    else:        count=count+1;        print "你所输入的数偏小!";

评论关闭