float

So far we have dealt with textual values (strings) and integer numbers (ints). Yet some applications require dealing with floating-point numbers. In python, those numbers are called floats. To read a floating-point number from the input, one can write a simple program:
a = int(input())
b = float(input())

print(a, type(a))
print(b, type(b))
print(a + b - 1)
In case the inputted numbers were 10 and 7.7, the program would print the following:
10 <class 'int'>
7.7 <class 'float'>
16.7
 
We can define floating-point numbers as regular variables:
pi = 3.14159265359
r = 2
print(2 * pi * r)
This program would compute the circumference of the circle on the right and would print 12.56637061436.
notion image

Challenge

Given two sides of a rectangle h and w, compute and print its surface area.
Input
2
3

Output
6
Input
1.1
3.5

Output
3.85
 
Note: You might notice that the python output for the second example is not exactly 3.85 but rather 3.8500000000000005. That’s because of the way our computers handle floating-point numbers. Watch this video to get more insights into how this magic happens:
Video preview
Video made by Computerphile (Floating-Point Numbers - Computerphile)
 
To check your solution you need to sign in
Sign in to continue