根据输入整数的大小给出不同输出

#!/usr/bin/env python  
#-*- coding:UTF-8 -*-

'''Usage of if'''

number = 20

running = True


while running:
    i = raw_input("Please guess a number or enter 'q\quit' to quit this game")
    if i == 'q' or i == 'quit':
       break
    #print type(i)
    print 'You entered: ',i
    if i.isdigit() == False:
       #print 'wrong input, enter a number please'
       print '输入错误,请输入一个整数'
       break
    else:
       i=int(i) #type(i)为str,转换类型
    if i == number:
       #print 'i=',i,'number',number
       print 'Congratulations, you guessed it! '
       break
    elif i > number:
       print 'No, it is lower than that.'
      else:
       print 'No, it is higger than that.'
 
print 'Done'

你可能感兴趣的:(根据输入整数的大小给出不同输出)