Python 比较数字会给出错误的答案
您正在比较两个字符串,而不是整数或浮点。 必须将输入转换为int或任何其他所需格式,然后进行比较。因此,完整的代码应该是:Python 比较数字会给出错误的答案,python,if-statement,Python,If Statement,您正在比较两个字符串,而不是整数或浮点。 必须将输入转换为int或任何其他所需格式,然后进行比较。因此,完整的代码应该是: first_num, second_num = input("Enter the first number: "), input("Enter the second number: ") if first_num > second_num : print(first_num, ' is the greatest num
first_num, second_num = input("Enter the first number: "), input("Enter the second number: ")
if first_num > second_num :
print(first_num, ' is the greatest number.')
else :
print(second_num, ' is the greatest number.')
这回答了你的问题吗@Epsi95在Python中没有诸如
string
、numeric
或casting之类的东西。这样的评论只会让初学者感到困惑。
first_num, second_num = int(input("Enter the first number: ")),
int(input("Enter the second number: "))
if first_num > second_num :
print(first_num, ' is the greatest number.')
else :
print(second_num, ' is the greatest number.')