0

Why 2+5=7 not 7.0?

24th Nov 2016, 6:03 AM
Krish Krishna
Krish Krishna - avatar
7 Answers
+ 3
data type of both inputs are integer so the output will be an interger
24th Nov 2016, 6:33 AM
Akwin Lopez
Akwin Lopez - avatar
+ 3
try 2.0+5 or 2+5.0 and see what happens :)
24th Nov 2016, 8:01 AM
Burey
Burey - avatar
+ 3
In programming language 7 and 7.0 are two different thing. 7 is an integer value and 7.0 is a float value. The plus + operator returns value based on the input. It works like this. int + int = int 2 + 5 = 7 int + float = float 2 + 5.0 = 7.0 float + int = float 2.0 + 5 = 7.0 float + float = float 2.0 + 5.0 = 7.0 float can contain integer numbers but integer can not contain float numbers. so most of the conditions returns float. But at least one of the inputs must be float.
24th Nov 2016, 3:02 PM
Cyrus Ornob Corraya
Cyrus Ornob Corraya - avatar
+ 3
Thanx for the like. :)
24th Nov 2016, 3:09 PM
Cyrus Ornob Corraya
Cyrus Ornob Corraya - avatar
+ 1
using + on ints return another int
24th Nov 2016, 6:14 AM
Wagner Silvestre Wuchryn Martins
Wagner Silvestre Wuchryn Martins - avatar
0
They are both integers. You need a float.
25th Nov 2016, 9:59 AM
Grady
Grady - avatar
0
Python is a loosely typed language, once you involve division in your code. Automatically the answer we'll have a precision or decimal value
25th Nov 2016, 3:10 PM
Joshua Ng andwe
Joshua Ng andwe - avatar