Найти - Пользователи
Полная версия: Ошибка в расчётах
Начало » Python для новичков » Ошибка в расчётах
1
icef
пишу:
pi = 3.14
s = pi + 2
l = len(str(s))
print("pi =", pi, ",", "s =", s, l)

Результат:
3.4.2 (v3.4.2:ab2c023a9432, Oct 6 2014, 22:16:31)
Python Type “help”, “copyright”, “credits” or “license” for more information.

pi = 3.14 , s = 5.140000000000001 17

Вопрос:
Откуда он взял единицу на пятнадцатом знаке после запятой?!
TroSer
уже отвечали тут http://python.su/forum/topic/26534/

It’s important to realize that this is, in a real sense, an illusion: the value in the machine is not exactly 1/10, you’re simply rounding the display of the true machine value. This fact becomes apparent as soon as you try to do arithmetic with these values

>>> 0.1 + 0.2
0.30000000000000004


ну и значение Pi можно брать из модуля math, math.pi
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB