Find Angle MBC - Python HackerRank Solution

Find Angle MBC - Python HackerRank Solution

Hello Friends, How are you? Today I am going to solve the HackerRank Python Find Angle MBC Problem with a very easy explanation. In this article, you will get more than one approach to solve this problem. So let's start-

{tocify} $title={Table of Contents}

Find Angle MBC - Python HackerRank Solution

HackerRank Python Find Angle MBC Solution - Problem Statement

Source: Find Angle MBC - Python HackerRank

ABC is a right triangle, 90° at B.
Therefore, angle ABC = 90°.
Point M is the midpoint of hypotenuse AC.

You are given the lengths AB and BC.
Your task is to find the angle of MBC in degrees.


Input Format

The first line contains the length of side AB.
The second line contains the length of side BC.

Constraints

0 < AB <= 100
0 < BC <= 100
Lengths AB and BC are natural numbers.

Output Format

Output angle MBC in degrees.
Note: Round the angle to the nearest integer.

Examples:

If the angle is 56.5000001°, then output 57°.
If the angle is 56.5000000°, then output 57°.
If the angle is 56.4999999°, then output 56°.

Sample Input 0

10 10 {codeBox}

Sample Output 0

45° {codeBox}

Python Find Angle MBC - Hacker Rank Solution

Approach I: Find Angle MBC HackerRank Python Solution

# ========================
#       Information
# ========================

# Name: Find Angle MBC - Python HackerRank Problem
# Direct Link: https://www.hackerrank.com/challenges/find-angle/problem
# Difficulty: Medium
# Max Score: 10
# Language: Python 3

# ========================
#         Solution Start
# ========================

# Find Angle MBC Python - Hacker Rank Solution

import math
ab=int(input())
bc=int(input())
ca=math.hypot(ab,bc)
mc=ca/2
bca=math.asin(1*ab/ca)
bm=math.sqrt((bc**2+mc**2)-(2*bc*mc*math.cos(bca)))
mbc=math.asin(math.sin(bca)*mc/bm)
print(int(round(math.degrees(mbc),0)),'\u00B0',sep='')

#your code ends here

# Find Angle MBC in Python - Hacker Rank Solution END
# MyEduWaves

Approach II: Find Angle MBC HackerRank Python Solution

# ========================
#       Information
# ========================

# Name: Find Angle MBC - Python HackerRank Problem
# Direct Link: https://www.hackerrank.com/challenges/find-angle/problem
# Difficulty: Medium
# Max Score: 10
# Language: Python 3

# ========================
#         Solution Start
# ========================

# Find Angle MBC Python - Hacker Rank Solution

import math

ab = input()
bc = input()

h = math.sqrt(ab**2 + bc**2)
h = h / 2.0
adj = bc / 2.0
print str(int(round(math.degrees(math.acos(adj/h))))) + "°"

#your code ends here

# Find Angle MBC in Python - Hacker Rank Solution END
# MyEduWaves


Disclaimer: The above Problem ( Python Find Angle MBC ) is generated by Hackerrank but the Solution is Provided by MyEduWaves. This tutorial is only for Educational and Learning purposes. Authority if any of the queries regarding this post or website fill the contact form.

I hope you have understood the solution to this HackerRank Problem. All these solutions will pass all the test cases. Now visit Python Find Angle MBC Hackerrank Problem and try to solve it again.

All the Best!

Post a Comment

Previous Post Next Post