纯编程盲...
原程序如下:
def isWholeNumber(s):
if s.isdigit():
return True
else:
return False
n = input(“Enter a whole number: “)
while not isWholeNumber(n):
print(“That was not a number. Try again.”)
n = input(“Enter a wholenumber: “)
x = int(n)
print(“Youtyped %d.” % x)
这个程序的问题就是如果我输入负整数,也会被判定为False导致输出Not a number.
怎么小改使它能认正负整数同时忽视其他数字?
谢谢了...Python真心不懂..
原程序如下:
def isWholeNumber(s):
if s.isdigit():
return True
else:
return False
n = input(“Enter a whole number: “)
while not isWholeNumber(n):
print(“That was not a number. Try again.”)
n = input(“Enter a wholenumber: “)
x = int(n)
print(“Youtyped %d.” % x)
这个程序的问题就是如果我输入负整数,也会被判定为False导致输出Not a number.
怎么小改使它能认正负整数同时忽视其他数字?
谢谢了...Python真心不懂..