def add_Number(a,b):
if isinstance(a,(int,float,long)) and isinstance(b,(int,float,long)):
return a + b
return None
def sub_Number(a,b):
if isinstance(a,(int,long,float)) and isinstance(b,(int,long,float)):
return a - b
return None
def RondNumber():
'''
练习:1 随机生成一个1-100中间的一个整数,然后你去输入一个数,如果大了,就提示大了,
然后让用户重新输入,如果是小了,那么提示小了,再让用户重新输入,
如果用户输入的数是等于随机生成的数,那么就一下你一共猜测的总数是多少,随机数是多少,结束程序
'''
ncount = 0 #计数
NumRand = int(random.random()*100)
while True:
ncount += 1
Number = int(raw_input('eter number:\n'))
if Number == NumRand:
print 'yes!'
sys.exit()
elif Number > NumRand:
print '输入大'
else:
print '输入小'
def game_Number():
random_number= random.randint(1,101)
times=0
while 1:
times+=1
user_input_number = input("please input your guess number:")
print user_input_number
print type(user_input_number)
if user_input_number == random_number:
print "you guess %s times" %times
print "the random number is %s" %random_number
break
elif user_input_number > random_number:
print "bigger,please try again!"
else:
print "less,please try again!"
if __name__ == "__main__":
#game_Number()
#RondNumber()
print add_Number(2,33)
共同学习,写下你的评论
评论加载中...
作者其他优质文章