When the code below takes input such as
5 (the length of the next input) 1 3 5 2 4
it accurately returns the maximum number and the minimum number.
However, when the code takes input that includes two-digit numbers such as
5 12 52 1 65 8
it returns 8 as the maximum number and 1 as the minimum.
How should I modify my code to always return the correct outputs?
num = int(input())
nums = input().split()
print(max(nums),min(nums))
CodePudding user response:
nums should be a list of integer and not list of string. currently it is list of string. you need to convert it to list of int.
nums = list(map(int, input().split()))
CodePudding user response:
You can try this out First take input as string then convert them to a list of numbers Hope It helps
n=(input("enter the numbers: "))
a=list(map(int,n.split()))
print(max(a),min(a))