Tip Calculator: Lesson 3



its not behaving weirdly
"Oops it seam "tip" is set to 0 instead of 0.15"

just that why cant we say 15/100, instead we have type "15.0/100"
is it a must to put decimals??



In Python 2.7, 15/100 is zero. Two integers in a division expression return an integer, and 0 is the only one available in this case.

>>> float(15) / 100


How come? Isnt 15 an integer? If not, sorry but I still don't get why is it a must to have decimals


Because of implicit type casting of number objects. When we give Python, 15, we give it an integer. Implicitly, this is type-cast as int. Give it 100 and again, an int. The result of the division will be int, which is 0.


ok I see then what is 15.0 exactly?
an int or something else?


ok so I read other posts and from I see 15.0 is something like a float value?
Uh well can you please explain "float values"? Thanks and cheers mate :smiley:


Now we're talking. The value has a type.

Once we explicitly declare one value as a float, it matters nor what type the other value is. The outcome will be a float.

What is a float? Anything that can be written as, 0.X where X is any uninterrupted number sequence. PI minus 3 is an example of a float.


okay but what is float value?


Late edit. Go back a post for reply.


okay thx :smiley:
I realised something: 15 will be considered an int. 15.0, though in mathematical terms is an integer, but it has to be specified to be "float value" so that the results we get is "float value" too right? Because when 15/100 is keyed in we get integer values but when 15.0/100 is in we get the float value aka the exact value am I right?


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.