Найти - Пользователи
Полная версия: 100 / 8 * 4 == 48
Начало » Python для новичков » 100 / 8 * 4 == 48
1
VadimK
 Python 2.7.5 (default, Nov  6 2016, 00:28:07) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print 100 / 8 * 4
48

Почему 48 ?
100 / 8 = 12.5
12.5 * 4 = 50

В чем я затупил ?
li_4
VadimK
Возможно оператор “/” во второй ветке применяет целочисленное деление ( без остатка ) и возвращает 12, а не 12.5?
FishHook
li_4
Возможно оператор “/” во второй ветке применяет целочисленное деление ( без остатка ) и возвращает 12, а не 12.5?
бинго!!!
VadimK
 >>> print type(100/8)
<type 'int'>
>>> print type(100)  
<type 'int'>
>>> print type(100.0)
<type 'float'>
>>> print 100.0 / 8 * 4
50.0

Да, так оно есть. Спасибо за подсказку.
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