dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
1.5 KiB
1.5 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 699c8e045ee7cb94ed2322db | Challenge 220: Largest Number | 29 | challenge-220 |
--description--
Given a string of numbers separated by various punctuation, return the largest number.
- The given string will only contain numbers and separators.
- Separators can be commas (
","), exclamation points ("!"), question marks ("?"), colons (":"), or semi-colons (";").
--hints--
largest_number("1,2") should return 2.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(largest_number("1,2"), 2)`)
}})
largest_number("4;15:60,26?52!0") should return 60.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(largest_number("4;15:60,26?52!0"), 60)`)
}})
largest_number("-402,-1032!-569:-947;-633?-800!-1012;-402,-723?-8102!-3011") should return -402.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(largest_number("-402,-1032!-569:-947;-633?-800!-1012;-402,-723?-8102!-3011"), -402)`)
}})
largest_number("12;-50,99.9,49.1!-10.1?88?16") should return 99.9.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(largest_number("12;-50,99.9,49.1!-10.1?88?16"), 99.9)`)
}})
--seed--
--seed-contents--
def largest_number(s):
return s
--solutions--
import re
def largest_number(s):
numbers = [float(n) for n in re.split(r'[,!?:;]', s)]
return max(numbers)