The minimum value of the Python character input method is not found

Asked 2 years ago, Updated 2 years ago, 70 views

n = str("Enter numbers separated by commas: ")))
x = min(n)
print("Minimum value is %s. " " %(x))

When I entered the number with the minimum value was I don't think I recognize the value of n.

n = [1, 2, 3, 4, 5]
x = min(x)
print("Minimum value is %s. " " %(x))

It comes out well if you type it like this, but what's the problem?

min python

2022-09-20 21:49

1 Answers

If you receive a string as a number, it becomes one string, as n = '1, 2, 3, 4, 5'.

And Python doesn't recognize that string as each number.

That's why trying to get a minimum value from a string doesn't get it.

If you want to find the minimum value among the numbers you have entered, you can enter them one by one and change them to numbers, or you can go through the following tasks.

>>> n = str("Enter a comma-separated number: "))
>>> n = list(map(lambda x: int(x), n.split(',')))
>>> n
[1, 2, 3, 4, 5]

The code above works when you enter numbers separated by commas as you wrote.


2022-09-20 21:49

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.