Q. Given a list of numbers, find maximum and minimum in this list.
Input Format:
The first line contains numbers separated by a space.
Output Format:
Print maximum and minimum separated by a space.
Example:
Input:
1 2 3 4 5
Output:
5 1
Solution:
Output:
Enter numbers separated by spaces:
5 3 8 0 67 23 6
The minimum and maximum numbers are:
0 67
.
Input Format:
The first line contains numbers separated by a space.
Output Format:
Print maximum and minimum separated by a space.
Example:
Input:
1 2 3 4 5
Output:
5 1
Solution:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print("Enter numbers separated by spaces:") | |
inputStr = input() | |
strList = inputStr.split() | |
numList = [int(x) for x in strList] | |
min = numList[0] | |
max = numList[0] | |
for x in numList: | |
if x < min: | |
min = x | |
if x > max: | |
max = x | |
print("The minimum and maximum numbers are:") | |
print(min, max) |
Output:
Enter numbers separated by spaces:
5 3 8 0 67 23 6
The minimum and maximum numbers are:
0 67
.
No comments:
Post a Comment