Operations | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Operations

Why do i get float if i divide in operations?Python

18th Nov 2018, 5:38 PM
Leaf
Leaf - avatar
5 Respostas
+ 6
Hello, šŸ˜Š Can you specifying your question correctly! Use the search bar! https://www.sololearn.com/post/10362/?ref=app Please, read our guidelines: https://www.sololearn.com/discuss/1316935/?ref=app An useful code for any new user here!;) https://code.sololearn.com/WvG0MJq2dQ6y/
18th Nov 2018, 6:36 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 1
Which language is that?
18th Nov 2018, 5:44 PM
Dlite
Dlite - avatar
+ 1
Thank you
19th Nov 2018, 1:44 AM
Leaf
Leaf - avatar
18th Nov 2018, 5:49 PM
Leaf
Leaf - avatar
0
If you divide 3 by 2, you get 1.5, right? If the result doesn't become a float, 3/2 would become 1 instead and the 0.5 is lost. In other languages like C this is actually the case: If you don't specifically say otherwise and you divide one int by another, the decimals disappear. Python is just designed the other way round: It creates a float whenever you divide, 'to be on the safe side'. If in Python you specifically don't want the decimals, you can use //.
18th Nov 2018, 11:40 PM
HonFu
HonFu - avatar