下面是我的代码,我是新的编码,所以需要你的帮助。 我不知道为什么会出现这个错误,因为当我尝试使用type()时,所有的都显示了类int,但是我在maxn和minn上出现了这个错误
n = int(input("Enter the length of list:"))
lst = input("Enter the numbers with a space:")
numbers = lst.split()
if len(numbers) == n:
maxn = -2147483647
minn = 2147483647
for number in numbers:
y = int(number)
if y > maxn:
maxn = number
if y < minn:
minn = number
print(maxn, minn)
else:
print("Numbers greater or less than length")
Traceback(last recent call):文件“test.py”,第9行,在if y>中; maxn:TypeError:“>” “int”和“str”的实例之间不支持
python中的输入总是被视为字符串,因此需要进行转换。 3号线将为您提供这方面的服务。 还有,你知道python可以处理任何大小的数字吗? 你可以大展身手!
n = int(input("Enter the length of list:"))
lst = input("Enter the numbers with a space:")
numbers = lst.split()
if len(numbers) == n:
maxn = -2147483647
minn = 2147483647
for number in numbers:
y = int(number)
if y > maxn:
maxn = y
if y < minn:
minn = y
print(maxn, minn)
else:
print("Numbers greater or less than length")