Question

In: Computer Science

def isPower(x, y): """ >>> isPower(4, 64) 3 >>> isPower(5, 81) -1 >>> isPower(7, 16807) 5...

def isPower(x, y):
    """
        >>> isPower(4, 64)
        3
        >>> isPower(5, 81)
        -1
        >>> isPower(7, 16807)
        5
    """
    # --- YOU CODE STARTS HERE
    def isPower(x, y):
        num = x
        count = 1
        while x < y:
            x *= num
            count += 1
        if x == y:
            return count
        return -1


def translate(translation, txt):
    """
        >>> myDict = {'up': 'down', 'down': 'up', 'left': 'right', 'right': 'left', '1': 'one'} 
        >>> text = 'Up down left Right forward 1 time' 
        >>> translate(myDict, text) 
        'down up right left forward one time'
    """
    # --- YOU CODE STARTS HERE
    def translate(translationDict, txt):
        words = txt.lower().split()
        for i in range(len(words)):
            if words[i] in translationDict:
                words[i] = translationDict[words[i]]
        return ' '.join(words)




def onlyTwo(x, y, z):
    """
        >>> onlyTwo(1, 2, 3)
        13
        >>> onlyTwo(3, 3, 2)
        18
        >>> onlyTwo(5, 5, 5)
        50
    """
    # --- YOU CODE STARTS HERE
    def onlyTwo(x, y, z):
        m1 = max(x, y, z)
        m2 = (x + y + z) - min(x, y, z) - m1
        return m1 * m1 + m2 * m2



def largeFactor(num):
    """
        >>> largeFactor(15) 
        5
        >>> largeFactor(24)
        12
        >>> largeFactor(7)
        1
    """
    # --- YOU CODE STARTS HERE
    def largeFactor(num):
        n = num - 1
        while n >= 1:
            if num % n == 0:
                return n
            n -= 1




def hailstone(num):
    """
        >>> hailstone(5)
        [5, 16, 8, 4, 2, 1]
        >>> hailstone(6)
        [6, 3, 10, 5, 16, 8, 4, 2, 1]
    """
    # --- YOU CODE STARTS HERE
    def hailstone(num):
        result = []
        while num > 1:
            result.append(num)
            if num % 2 == 0:
                num = num // 2
            else:
                num = 3 * num + 1
        result.append(num)
        return result

if any wrong with my code

Solutions

Expert Solution

def isPower(x, y):
    """
        >>> isPower(4, 64)
        3
        >>> isPower(5, 81)
        -1
        >>> isPower(7, 16807)
        5
    """
    num = x
    count = 1
    while x < y:
        x *= num
        count += 1
    if x == y:
        return count
    return -1


def translate(translation, txt):
    """
        >>> myDict = {'up': 'down', 'down': 'up', 'left': 'right', 'right': 'left', '1': 'one'}
        >>> text = 'Up down left Right forward 1 time'
        >>> translate(myDict, text)
        'down up right left forward one time'
    """
    words = txt.lower().split()
    for i in range(len(words)):
        if words[i] in translation:
            words[i] = translation[words[i]]
    return ' '.join(words)


def onlyTwo(x, y, z):
    """
        >>> onlyTwo(1, 2, 3)
        13
        >>> onlyTwo(3, 3, 2)
        18
        >>> onlyTwo(5, 5, 5)
        50
    """
    m1 = max(x, y, z)
    m2 = (x + y + z) - min(x, y, z) - m1
    return m1 * m1 + m2 * m2


def largeFactor(num):
    """
        >>> largeFactor(15)
        5
        >>> largeFactor(24)
        12
        >>> largeFactor(7)
        1
    """

    n = num - 1
    while n >= 1:
        if num % n == 0:
            return n
        n -= 1


def hailstone(num):
    """
        >>> hailstone(5)
        [5, 16, 8, 4, 2, 1]
        >>> hailstone(6)
        [6, 3, 10, 5, 16, 8, 4, 2, 1]
    """
    # --- YOU CODE STARTS HERE
    result = []
    while num > 1:
        result.append(num)
        if num % 2 == 0:
            num = num // 2
        else:
            num = 3 * num + 1
    result.append(num)
    return result


Related Solutions

ID X Y 1 2 3 2 3 6 3 4 6 4 5 7 5...
ID X Y 1 2 3 2 3 6 3 4 6 4 5 7 5 8 7 6 5 7 7 6 7 8 8 8 9 7 8 10 12 11 Test the significance of the correlation coefficient. Then use math test scores (X) to predict physics test scores (Y).  Do the following: Create a scatterplot of X and Y. Write the regression equation and interpret the regression coefficients (i.e., intercept and slope). Predict the physics score for each....
Maria says that 4 2/3 x 7 1/5 = 4 x 7 + 2/3 x 1/5....
Maria says that 4 2/3 x 7 1/5 = 4 x 7 + 2/3 x 1/5. Explain why Maria has made a good attempt, but her answer is not correct. Explain how to work with what Maria has already written and modify it to get the correct answer. In other words, don’t just start from scratch and show Maria how to do the problem, but rather take what she has already written, use it, and make it mathematically correct. Which...
Given: x y -5 1 -4 5 -3 4 -2 7 -1 10 0 8 1...
Given: x y -5 1 -4 5 -3 4 -2 7 -1 10 0 8 1 9 2 13 3 14 4 13 5 18 What are the confidence limits (alpha = 0.05) for the true mean value of Y when X = 3?
Step 2 Data Set A x 1 2 3 4 5 6 7 y 7 7...
Step 2 Data Set A x 1 2 3 4 5 6 7 y 7 7 7 9 9 9 10 Data Set B x 1 2 3 4 5 6 7 8 9 10 11 y 4 6 6 6 8 9 9 9 10 10 10 Step 2 Find the equation for the least-squares line, and graph the line on the scatter plot. Find the sample correlation coefficient r and the coefficient of determination r2. Is r significant?...
X 1 3 5 3 4 4 Y 2 5 4 3 4 6 A: Plot...
X 1 3 5 3 4 4 Y 2 5 4 3 4 6 A: Plot the date B: find the line of best fit C: determine ŷ AT x=3 D: Find r and r^2 E: explain r and r^2
x 2 8 5 9 4 3 9 6 7 8 y 3 6 5 7...
x 2 8 5 9 4 3 9 6 7 8 y 3 6 5 7 9 7 4 6 9 9 -5.48x + 0.17 5.48x + 0.17 -0.17x + 5.48 0.17x + 5.48
x 3, 4, 5, 7, 8 y 3, 7, 6, 13, 14 (a) Find the estimates...
x 3, 4, 5, 7, 8 y 3, 7, 6, 13, 14 (a) Find the estimates of Bo and B1. Bo=bo= _____ (Round to three decimal places as needed.) B1=b1= ______(Round to four decimal places as needed.) (b) Compute the standard error the point estimate for se= ____ (c) Assuming the residuals are normally distributed, determine Sb1=____ (Round to four decimal places as needed.) (d) Assuming the residuals are normally distributed, test HoB1=0 versus H1:B1/=0 at the a=0.05 level of...
For the data set shown​ below. x   y 3   4 4   5 5   8 7   12...
For the data set shown​ below. x   y 3   4 4   5 5   8 7   12 8   15 Find the estimates of β0 and β1. β0≈b0=-3.256 ​ (Round to three decimal places as​ needed.) β1≈b1=2.233 (Round to three decimal places as​ needed.) (b) Compute the standard​ error, the point estimate for σ. Se=0.5972 ​(Round to four decimal places as​ needed.) ​(c) Assuming the residuals are normally​ distributed, determine sb1. sb1=0.144 ​(Round to three decimal places as​ needed.) ​(d) Assuming the...
3. Consider the following data for two variables, x and y. x   2 3 4 5 7...
3. Consider the following data for two variables, x and y. x   2 3 4 5 7 7 7 8 9 y 4 5 4 6 4 6 9 5 11 a. Does there appear to be a linear relationship between x and y? Explain. b. Develop the estimated regression equation relating x and y. c. Plot the standardized residuals versus yˆ for the estimated regression equation developed in part (b). Do the model assumptions appear to be satisfied? Explain. d....
4) Let ? = {2, 3, 5, 7}, ? = {3, 5, 7}, ? = {1,...
4) Let ? = {2, 3, 5, 7}, ? = {3, 5, 7}, ? = {1, 7}. Answer the following questions, giving reasons for your answers. a) Is ? ⊆ ?? b)Is ? ⊆ ?? c) Is ? ⊂ ?? d) Is ? ⊆ ?? e) Is ? ⊆ ?? 5) Let ? = {1, 3, 4} and ? = {2, 3, 6}. Use set-roster notation to write each of the following sets, and indicate the number of elements in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT