I have 2 numbers and I want to divide them and the result I want is like this:
a = [12, 14]
b = [5, 3]
for k in range(len(a)):
print(math.ceil(int(a[k]) / int(b[k])))
I want the output look like this:
12 / 5 = 2.4 => 2
14 / 3 = 4.6 => 5
I have 2 numbers and I want to divide them and the result I want is like this:
a = [12, 14]
b = [5, 3]
for k in range(len(a)):
print(math.ceil(int(a[k]) / int(b[k])))
I want the output look like this:
12 / 5 = 2.4 => 2
14 / 3 = 4.6 => 5
why use math.ceil
when you can use round()
.
print(round(int(a[k]) / int(b[k])))
with round
you can control how many number you need:
>>> print(round((a[k] / b[k]), 3))
2.4
4.667
You can use f-string
and control how many numbers you need:
>>> print(f'{(a[k] / b[k]):.3f}')
2.400
4.667
just replace math.ceil
with round
as in :
a = [12, 14]
b = [5, 3]
for k in range(len(a)):
print(a[k], "/", b[k], "=>", round(int(a[k]) / int(b[k])))
Instead of math.ceil
which is the ceiling of a number, so for example ⌈2.4⌉ = 3, ⌈2.8⌉ = 3 use just round()
.
a = [12, 14]
b = [5, 3]
for k in range(len(a)):
print(round(int(a[k]) / int(b[k])))