我正在尝试比较用户收到的输入,以检查输入是否实际上是数字。这是我到目前为止所拥有的:
numstring = input("Choose a number between 1 and 10")
然后比较我有这样的方法:
def check(a):
if int(a) == int:
print("It's a number!")
else:
print("It's not a number!")
它总是打印出它不是一个数字,即使它是。
这个程序的目标:我正在做一个猜谜游戏:
import random
numstring = input("Choose a number between 1 and 10")
def check(a):
if int(a) == int:
print("It's a number!")
else:
print("It's not a number!")
if abs(int(a)) < 1:
print("You chose a number less than one!")
elif abs(int(a)) > 10:
print("You chose a number more than ten!")
else:
randomnum = random.randint(1, 10)
randomnumstring = str(abs(randomnum))
if randomnum == abs(int(a)):
print("You won! You chose " + a + "and the computer chose " + randomnumstring)
else:
print("You lost! You chose " + a + " and the computer chose " + randomnumstring)
check(numstring)
谢谢你的帮助!实际的代码有效,但只是无法检查它。