Finding the minimum and maximum values from a given range of input values in Python?



Hello guys this is Satyam,again back with another awesome blog and in this blog I am going to show you how you can find the minimum and maximum values from a given range of input values in Python without using any in-built methods such as max() and min().So guys first of all please have a look at the code below:

Code:
max_value = None
min_value = None

for i in range(1,6):
    num = input("Enter a number: ")
    num = int(num)
    if max_value is None :
        max_value = num
    elif max_value < num :
        max_value = num
    if min_value is None :
        min_value = num
    elif num < min_value :
        min_value = num

print("Maximum is", max_value)
print("Minimum is", min_value)


So guys the code is very clear,It is first assuming that the maximum and minimum values are None and in the if condition it's checking some condition and finally the output is presented.

Thanks for Reading

No comments: