Need help returning min() value of list? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Need help returning min() value of list? (/thread-22371.html) |
Need help returning min() value of list? - edwdas - Nov-10-2019 Howdy, I have a feeling that my issue lies within my second function. The Max function works for returning the single highest digit however the min function returns a blank value lst = [] def sort_max(): max(lst) return (sorted(max(list(lst)))[-1]) def sort_min(): min(lst) return (sorted(min(list(lst)))[+1]) while True: usrInput = (input("List ")) if usrInput == "": print("Min", sort_min(), "Max", sort_max()) break lst.append(usrInput) RE: Need help returning min() value of list? - jefsummers - Nov-10-2019 I'm a bit confused as to what you are wanting to do. So, posing some questions that are aimed at getting you to think. Looking at lines 6 and 10, 1. What do you think list(lst) will do for you? 2. Does max(any list) give you a list that can be sorted, or a single item? Suggest you look at what the result of each step would be by a series of print statements. I think that will show you the answer RE: Need help returning min() value of list? - edwdas - Nov-10-2019 Sorry for the confusion posted this a little late. So what i need is for lst to store user input of multiple numbers in one line e.g. the user should be able to input 8 7 6 5 4 3 2 1 in one line with spaces. Then i need to it to print the highest/lowest digit entered e.g. 8 and 1. Right now it only points the 8 and will blank out on the 1 if i enter the exampled input RE: Need help returning min() value of list? - snippsat - Nov-10-2019 Here some hint,first step is to get user input to be a list of integers. Then will min() and max() do what name hint about,without using sorted() or other stuff. >>> usr_input = input("Enter numbers with space between: ") Enter numbers with space between: 8 7 6 5 4 3 2 1 >>> usr_input '8 7 6 5 4 3 2 1' >>> usr_input.split() ['8', '7', '6', '5', '4', '3', '2', '1'] # To make a list with integers >>> lst = [int(i) for i in usr_input.split()] >>> lst [8, 7, 6, 5, 4, 3, 2, 1] >>> max(lst) 8 >>> print(f'Min numer is <{min(lst)}> Max number is <{max(lst)}>') Min numer is <1> Max number is <8> |