w3resource

Python: Find the highest and lowest number from a given string of space separated integers

Python Basic - 1: Exercise-97 with Solution

Write a Python program to find the highest and lowest number from a given string of space-separated integers.

Sample Solution:

Python Code:

def highest_lowest_num(str1):
 num_list = list(map(int, str1.split()))
 return max(num_list), min(num_list)
text = "1 4 5 77 9 0"
print("Original string:", text)
print("Highest and lowest number of the said string:",highest_lowest_num(text))
text = "-1 -4 -5 -77 -9 0"
print("\nOriginal string:", text)
print("Highest and lowest number of the said string:",highest_lowest_num(text))
text = "0 0"
print("\nOriginal string:", text)
print("Highest and lowest number of the said string:",highest_lowest_num(text))

Sample Output:

Original string: 1 4 5 77 9 0
Highest and lowest number of the said string: (77, 0)

Original string: -1 -4 -5 -77 -9 0
Highest and lowest number of the said string: (0, -77)

Original string: 0 0
Highest and lowest number of the said string: (0, 0)

Pictorial Presentation:

Python: Find the highest and lowest number from a given string of space separated integers.
Python: Find the highest and lowest number from a given string of space separated integers.

Flowchart:

Flowchart: Python - Find the highest and lowest number from a given string of space separated integers.

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to check whether a given number is a narcissistic number or not.
Next: Write a Python program to check whether a sequence of numbers has an increasing trend or not.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.