-1

I am new to python. I divided two numbers but, I no get decimal part.

amount = 1000
people = 3
average = total_amount/total_people
print average

I am getting o nly 333 not 333.33 How to solve this? I am ubuntu user.

Jongware
  • 22,200
  • 8
  • 54
  • 100
blabla
  • 1
  • 1

2 Answers2

0

In Python2 you should convert one of the numbers to float:

average = float(total_amount) / total_people

Another option is to use the backported division operator from Python3:

from __future__ import division

amount = 1000
people = 3
average = total_amount / total_people
print average
>> 333.333333

(This will work if you of course use the correct variable names).

DeepSpace
  • 78,697
  • 11
  • 109
  • 154
0
amount = 1000
people = 3
average = float(amount)/float(people)
print average

OR

from __future__ import division
amount = 1000
people = 3
average = amount/people
print average
nitroman
  • 643
  • 2
  • 10
  • 25