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.

3
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Aug 20, 2023 at 2:48
  • print('\xb0') prints the °. Commented Aug 20, 2023 at 3:55
  • 1
    What do you mean "the platform does not allow it"? What platform? What happens when you try? In fact, what code did you try exactly? Commented Aug 20, 2023 at 4:06

1 Answer 1

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")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.