Tip Calculator: Lesson 3


#1



https://www.codecademy.com/courses/python-beginner-GB6hM/0/3?curriculum_id=4f89dab3d788890003000096#


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??


tip=15/100


#2

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
0.15

#3

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


#4

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.


#5

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


#6

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:


#7

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.


#8

okay but what is float value?


#9

Late edit. Go back a post for reply.


#10

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?


#11

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