Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 1: python programming, using python 3. a) Write a function mh2kh(s) tha

ID: 3872422 • Letter: Q

Question

Question 1:

python programming, using python 3.

a) Write a function mh2kh(s) that given the speed, s, expressed in miles/hour returns the same speed expressed in kilometres/hour.

b) Two numbers a and b are called pythagorean pair if both a and b are integers and there exists an integer c such that a2 + b2 = c2. Write a function pythagorean_pair(a,b) that takes two integers a and b as input and returns True if a and b are pythagorean pair and False otherwise.

How the testing of the question looks like:

testing Question 1a) >>>

>>> mh2kh(5)

8.0467

>>>
>>> mh2kh(110.4)

177.67113600000002

# testing Question 1b) >>>

>>> pythagorean_pair(2,2)

False
>>> pythagorean_pair(6,2)

False
>>> pythagorean_pair(6,8)
True
>>> pythagorean_pair(300,-400)

True

Explanation / Answer

import math
# 1mps = 1.60934 kps (mps - miles per second, kps - kilometers per second
def mh2kh(s):
    return s*1.60934

def pythagorean_pair(a,b):
    x=((a*a) + (b*b))
    y=math.sqrt((a*a)+(b*b))
    if x==y*y:
        print ("Ture")
    else:
        print ("False")
              
print(mh2kh(5))
print(mh2kh(110.4))
pythagorean_pair(2,2)
pythagorean_pair(6,2)
pythagorean_pair(6,8)
pythagorean_pair(300,-400)
'''
Output
-------
>>>
======== RESTART: F:/personal/PersonalData/Chegg/29-Sep-2017/mh2kh.py ========
8.0467
177.67113600000002
False
False
Ture
Ture
>>>
'''

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote