Python: Find the largest number where commas or periods are decimal points
Python Programming Puzzles: Exercise-26 with Solution
Write a Python program to find the largest number where commas or periods are decimal points.
Input: ['100', '102,1', '101.1'] Output: 102.1
Pictorial Presentation:

Sample Solution-1:
Python Code:
#License: https://bit.ly/3oLErEI
def test(str_nums):
return max(float(s.replace(",", ".")) for s in str_nums)
str_nums = ["100", "102,1", "101.1"]
print("Original list:")
print(str_nums)
print("Largest number where commas or periods are decimal points:")
print(test(str_nums))
Sample Output:
Original list: ['100', '102,1', '101.1'] Largest number where commas or periods are decimal points: 102.1
Flowchart:

Sample Solution-2:
Python Code:
#License: https://bit.ly/3oLErEI
def test(str_nums):
numbers = []
for s in str_nums:
numbers.append(float(s.replace(",", ".")))
numbers.sort()
return numbers[-1]
str_nums = ["100", "102,1", "103.1"]
print("Original list:")
print(str_nums)
print("Largest number where commas or periods are decimal points:")
print(test(str_nums))
Sample Output:
Original list: ['100', '102,1', '103.1'] Largest number where commas or periods are decimal points: 103.1
Flowchart:

Python Code Editor :
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Find the XOR of two given strings interpreted as binary numbers.
Next: Find x that minimizes mean squared deviation from a given list of numbers.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join