python 做一个循环 要求输入大于0的数字 判断其不为负数或者字母
heyandc LV12 2013-11-25
def Setlimits(): print ('Starting Game limits') print ('Low must be 0 or greater. High must be greater than low.') left=input('Please enter a Low bound: ') def Low1(x): while x < 0: x = int (input('... def Setlimits():
print ('Starting Game limits')
print ('Low must be 0 or greater. High must be greater than low.')
left=input('Please enter a Low bound: ')
def Low1(x):
while x < 0:
x = int (input('Low bound must be 0 or greater: '))
return print('Low bound is ',x)
def Low2(x):
Low(x)
def Low(x):
while True:
try:
y=int(x)
if y < 0:
y = int(input('Low bound must be 0 or greater: '))
Low1(y)
break
else :
print('Low bound is ',y)
break
except ValueError:
y=int(input('Low bound must be a valid integer:'))
Low2(y)
Low(left)
Setlimits()
麻烦看下我写的这个 连续输入2个字符就会出错 输入一个负数后再输字符 又需要输入2次正数。。。好多问题 展开