Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Need help returning min() value of list?
#1
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)

Quote
#2
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
Quote
#3
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
Quote
#4
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>
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  API call returning list value of 'None' jimbone30 5 396 Jun-14-2019, 07:42 PM
Last Post: jimbone30

Forum Jump:


Users browsing this thread: 1 Guest(s)