当我执行以下代码时,由于某种原因,我收到一条奇怪的错误消息。
我尝试将int更改为float,但没有任何效果。
number = float(input("Please enter an integer number."))
if number % 1 == 0:
list = []
list.append(number)
add = input("Would you like to add any more integers? Type Y for yes and N for no.")
while add == "Y":
newnumber = input("What is the next integer?")
list.append([newnumber])
add = input("Would you like to add any more integers? Type Y for yes and N for no.")
if add == "N":
print("Length: %s" % len(list))
print("Minimum: %s" % int(min(list)))
else:
print("This is not an integer. Please restart.")
这发生在第12行或print(“ Minimum ...)行中。 “列表”和“浮动”实例之间不支持“ <” 是错误消息。 我认为我从来没有将字符<放在第12行。
我们将不胜感激。
答案 0 :(得分:0)
请将list.append([newnumber])更改为list.append(int(newnumber)),因为您要附加一个列表([8.0,['9'],['6']])而不是另一个整数在列表中
number = float(input("Please enter an integer number."))
if number % 1 == 0:
list = []
list.append(number)
add = input("Would you like to add any more integers? Type Y for yes and N for no.")
while add == "Y":
newnumber = input("What is the next integer?")
list.append(int(newnumber))
add = input("Would you like to add any more integers? Type Y for yes and N for no.")
if add == "N":
print("Length: %s" % len(list))
print("Minimum: %s" % int(min(list)))
else:
print("This is not an integer. Please restart.")