Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Question in regards of your video - how come when you do 16/4 the Workspace output is 4.0 - you dividing integers so output should be an integer. I have tried it in the terminal of my mac and output is integer 4 - even is you do previous 4+1.5 = 5.5 is float and then 16/4 = 4 integer - probably you have a bug in the workspace.
Phil Thomas4,563 Points
This is discussed in the teachers notes, which contains a link to a full explanation in the Python documentation:
Noticed on my mac when running "python" (2.7.10) 16/4 returns 4, however, if I run "python3" (3.6.4) it returns 4.0. The workspace is running 3.6.4 as well, so it returning a float is correct.
However in Python3, if you do 16//4 it will return an integer.
Note: even with // if either of the numbers is a float, it will return the float.
I figure that out in python 2.7 is 0.1+0.1+0.1 = 0.30000000000000004 but in python 3 it is precisely 0.3 - question is why
It also discussed in the video itself, the operation returns a float. If you wish to have integer division. You can do the following operations
23 // 3 23 % 4 #this will give you the remainder
Hai Phan2,442 Points
Craig said you always will get a float when you do devision, and it true when I do 16/4 in my Windows PC, always 4.0
now this session start very complicated. hard to understand.
plz make an simple video its hard to understand
Remy Duijsens970 Points
This is because there are different Python version used. Python updates from time to time, currently the community is separated in the "old" Python version 2.7 and the newer version Python 3.7. The Workspace uses this newer version which comes with new functionalities. The division operator (/) now always returns answers as floating point number. If you wish to use the old functionality you have to use a double forward slash (//) for integer division. You could of course also download the newer version of python at python.org!