0

I am trying to do the find-angle challenge in hacker rank, I got the value of the angle as an integer but hacker rank requires me to give the output with " ° " symbol at the end, how do I tackle this, P.S. the platform does not allow ascii characters. this was the code I came up with

import math
ab=int(input())
bc=int(input())
hypotenuse=math.sqrt(ab**2+bc**2)
mc=hypotenuse/2
angle_bmc=90
mb=math.sqrt(bc**2-mc**2)
result_in_radians=math.asin(mc/bc)
result_in_degrees=math.degrees(result_in_radians)

trying to print output as degrees, I tried using formatting and printing the ascii code but the platform does not allow it.

1 Answers1

0
>>> "\xb0"
'°'
>>> u'\N{DEGREE SIGN}'
'°'
>>> chr(176)
'°'
>>> '\u00b0'
'°'

You can search 'Unicode degree' to get result "Degree sign U+00B0". Works with other symbols too.

With your code, you can do :

import math
ab=int(input())
bc=int(input())
hypotenuse=math.sqrt(ab**2+bc**2)
mc=hypotenuse/2
angle_bmc=90
mb=math.sqrt(bc**2-mc**2)
result_in_radians=math.asin(mc/bc)
result_in_degrees=math.degrees(result_in_radians)

print("Result (rad): ", result_in_radians, "rad")
print("Result (deg): ", result_in_degrees, "\u00b0")
Eeark
  • 13
  • 5