PYTHON CORE · LESSON 13

Fractional numbers

When the whole is small · about 11 minutes

Learning with progressRead the summary for free. To save the work, log in to the account.
STEP 1

Part of the whole

For a point number, use float. In Python, the decimal part is separated by a point, not a comma.

weight = float(input("Вес? "))

✦ The answer 2.5 will be 2.5.

STEP 2

Add fractional numbers

With fractional numbers can be considered the same as with wholes.

weight = float(input("Вес? "))
print(weight + 0.5)

✦ Type 2.5 and 3.0 will appear.

IN-CLASS PRACTICE

Type the code yourself

Reprint the example. The fractional number is entered through float.

length = float(input("Длина? "))
print(length + 1.5)
Open the editor for class work
HOMEWORK

Solve it yourself

Ask the fractional price, save it in price and output the price plus 0.5. Think of the text yourself.

The answer is hidden. Use similar examples from the lesson notes.

Opening up your homework