![](/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.