Write a programExercise 4/4Intermediate30 XP

Reading a decimal number

Task

Write a function nacitaj_float() that keeps reading input lines until it gets a valid decimal number, then returns it. The number may also be written with a decimal comma (3,5). After every invalid line it prints Neplatné číslo, skús znova. (invalid number, try again).

If the input is abc and then 3,5, the function prints one message and returns 3.5.

Examples

  • Call

    print(nacitaj_float())

    Expected output

    Neplatné číslo, skús znova.
    3.5

After you submit, 5 hidden tests will also check your solution: valid straight away, an empty line, two commas, spaces around the number, returns a float.

Python starts the first time you run code.

Ctrl+Enter runs the program. Tab indents. Press Esc, then Tab, to leave the editor.

Input (stdin)

Each line = one call to input().

Output

Hints

Try it yourself first. Each hint reveals a little more - and lowers the reward a little.

Signed out, hints are free - but no XP is awarded either.

Solution

The solution unlocks after the last hint.