I wanted help in an exercise I need to find the smallest / largest number between a , b , c in python without using conditional operator
Prohibited The input contains a single line with three integers a, b and c separated by a space in white.
Exit Your program should produce the largest value of a, b, and c. There must be no blanks and/or empty lines in the output produced.
Example
input (a line)
1 2 3
Exit
3
CodePudding user response:
Let's assume the input
numbers is interactively from the user. You could try to use max
and min
to get the largest and smallest number, and avoid using conditional
operator. Let me know if there is any question.
lst = input('type in three numbers: (sep. by spaces)').split() # type in 11 22 3
print(lst) # ['11', '22', '3'] for example,
print(f' largest number: {max((lst), key=int)} ') # 22