![](/img/trans.png)
[英]Python regex: Reject one two-digit number and accept other two-digit numbers
[英]Python: Question about the usage of max() and min() when the input numbers are two-digit
当下面的代码接受输入时,例如
5(下一个输入的长度) 1 3 5 2 4
它准确地返回最大数和最小数。
但是,当代码接受包含两位数的输入时,例如
5 12 52 1 65 8
它返回 8 作为最大数,1 作为最小数。
我应该如何修改我的代码以始终返回正确的输出?
数字 = 整数(输入())
nums = input().split()
打印(最大(数字),最小(数字))
nums 应该是 integer 的列表而不是字符串列表。 目前它是字符串列表。 您需要将其转换为 int 列表。
nums = list(map(int, input().split()))
你可以试试这个首先将输入作为字符串然后将它们转换为数字列表希望它有帮助
n=(input("enter the numbers: "))
a=list(map(int,n.split()))
print(max(a),min(a))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.