Question

Python, smallestFactor() 1. #Given an integer n (which you can assume is positive), # return the...

Python, smallestFactor()

1.

#Given an integer n (which you can assume is positive),
# return the largest factor of n less than n.
# If n is 1, then you should return 1.
def largestFactor(n):
# TO DO: Finish function
return

Homework Answers

Answer #1

The below code is to find the lasrgest factor of any given number.

A number i is factor of a given number n if remainder of n/i = 0

The largest remainder of a number n is the maximum of all remainders excluding n



def largestFactor(n):
    if n==1:             # when n is 1, the largest factor is 1
        return 1
    for i in range(1,n):   # loop from 1 to (n-1)
        if n%i ==0:            #if the remainder is 0 then i is a factor of n
            res = i             # we need the last factor which is the largest factor
    return res

print("Enter the number n : ")
n = input()
n = int(n)
res = largestFactor(n)
print("Largest factor of the number ",n,"is: ",res)

Output 1:

Output 2:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
An integer 'n' greater than 1 is prime if its only positive divisor is 1 or...
An integer 'n' greater than 1 is prime if its only positive divisor is 1 or itself. For example, 2, 3, 5, and 7 are prime numbers, but 4, 6, 8, and 9 are not. Write a python program that defines a function isPrime (number) with the following header: def isPrime (number): that checks whether a number is prime or not. Use that function in your main program to count the number of prime numbers that are less than 5000....
python define prime number, return Ture False do not use loop or recursion using map() can...
python define prime number, return Ture False do not use loop or recursion using map() can using divides() def divides(n): def div(m): return n%k==0 return div code must be less than 4lines
TO BE DONE IN PYTHON: Write a function `lowest_integer()` which takes 2 input arguments: 1)a function...
TO BE DONE IN PYTHON: Write a function `lowest_integer()` which takes 2 input arguments: 1)a function `g` representing an increasing function g(x) 2) a number `gmin`, and returns an integer `nmin` such that nmin>0 is the smallest integer that satisfies g(nmin)>gmin. test: def g(n): return 2*n print(lowest_integer(g, 10)) Output: 6
Q2- Write a function solution that, given an integer N, returns the maximum possible value obtained...
Q2- Write a function solution that, given an integer N, returns the maximum possible value obtained by inserting one '5' digit inside the decimal representation of integer N. Examples: 1. Given N = 268, the function should return 5268. 2. Given N = 670, the function should return 6750. 3. Given N = 0, the function should return 50. 4. Given N = −999, the function should return −5999. Assume that: N is an integer within the range [−8,000..8,000].
In Matlab, write a function that takes a relatively small (less than 100 billion) positive integer...
In Matlab, write a function that takes a relatively small (less than 100 billion) positive integer input and outputs the prime factorization of that integer using as few built-in functions as possible. Explain the processes with comments. NOTE: Do not use the functions factor(n), primes(n), or isprime(n). You should be able to write out what these functions do yourself if you want to be able to do something similar.
a. Find an algorithm for solving the following problem: Given a positive integer n, find the...
a. Find an algorithm for solving the following problem: Given a positive integer n, find the list of positive integers whose product is the largest among all the lists of positive integers whose sum is n. For example, if n is 4, the desired list is 2, 2 because 2 × 2 is larger than 1 × 1 × 1 × 1, 2 × 1 × 1, and 3 × 1. If n is 5, the desired list is 2,...
question: Complete the function remove number such that given a list of integers and an integer...
question: Complete the function remove number such that given a list of integers and an integer n, the function removes every instance of n from the list. Remember that this function needs to modify the list, not return a new list. please edit the Python form without errors def remove_number(lst: List[int], number: int) -> None:     """         Remove every instance of number in lst. Do this         *in-place*, i.e. *modify* the list. Do NOT         return a new list....
Python: Associate the average of the numbers from 1 to n (where n is a positive...
Python: Associate the average of the numbers from 1 to n (where n is a positive integer value) with the variable avg.
Implement the following functions in the given code: def random_suit_number(): def get_card_suit_string_from_number(n): def random_value_number(): def get_card_value_string_from_number(n):...
Implement the following functions in the given code: def random_suit_number(): def get_card_suit_string_from_number(n): def random_value_number(): def get_card_value_string_from_number(n): def is_leap_year(year): def get_letter_grade_version_1(x): def get_letter_grade_version_2(x): def get_letter_grade_version_3(x): Pay careful attention to the three different versions of the number-grade-to-letter-grade functions. Their behaviors are subtly different. Use the function descriptions provided in the code to replace the pass keyword with the necessary code. Remember: Parameters contain values that are passed in by the caller. You will need to make use of the parameters that each...
write a function that returns the value of the binomial expansion for a positive (or zero)...
write a function that returns the value of the binomial expansion for a positive (or zero) integer power n and any valid value of x. first write a function that calculates the value of the rth term. This all has to be done without importing any packages in python. Current code, def binomial_term_L1(x,n): return (1+x)**n but having trouble getting the code for the rth term to work.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT