#Rounding up function

1 messages · Page 1 of 1 (latest)

solar edge
#

I want it round up as 1.35 and 1.44. But when I did round(first_c/first_d) it gave me 1 as a result. How would I make it the way I want it?

random rain
#

;compile

import math

x = 5/3
y = round(x, 2)

print(f"X: {x}")
print(f"Y: {y}")

# You can also use string formating
print(f"f-string: {x:.2f}") # prefered
print("format: {:.2f}".format(x))
print(f"old style: %.2f"% x)
raven jettyBOT
#
Program Output
X: 1.6666666666666667
Y: 1.67
f-string: 1.67
format: 1.67
old style: 1.67
random rain
#

Btw, you should always space your imports from your code it increase readability which makes your code easier to read, write and debug.

Your call to math.pi on line 2 doesn't do anything.

solar edge
#

oh

pallid cloud
random rain
#

;compile

from math import sqrt


def hypotenuses(a: float, b: float) -> float:
  return sqrt(a**2 + b**2)


if __name__ == '__main__':
  a = 5
  b = 10
  c = hypotenuses(a, b)

  print(f"{a}^2 + {b}^2 = {c:.2f}")
raven jettyBOT
#
Program Output
5^2 + 10^2 = 11.18
random rain
#

Concrete exemple