P
P
progr232021-08-26 17:17:35
Python
progr23, 2021-08-26 17:17:35

How to find the largest value from a list?

Good afternoon! Help me solve the task, I don’t understand how to use input () here so that it receives values ​​\u200b\u200bfrom the user and displays the largest one?

Task:
Write a program that will ask for input numbers (comma-separated on one line) and print the largest value from the list.

Restriction: You cannot use a ready-made function for finding the maximum (for example, max() ), ready-made functions and sorting methods (for example, sort() , sorted() ), the set() function .

Input format: 1, 2, 3, 6, 7
Output format: 7

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
sswwssww, 2021-08-26
@progr23

max_number = float('-inf')
[(max_number := i) for i in map(int, input().split(',')) if i > max_number]

A
Alan Gibizov, 2021-08-26
@phaggi

number_list = [int(i) for i in input().split(',')]

D
Drill, 2021-08-29
@Drill

from functools import reduce

print(reduce(lambda x,y: (x, y)[x<y], map(int, input().split(','))))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question