Question

Using python Write a Python function called sgm that requests a positive integer n and returns...

Using python

Write a Python function called sgm that requests a positive integer n and returns the series geometric mean of the numbers 1,2,3, . . . n. For example sgm(5) =

(5 x 4 x 3 x 2 x 1)1/5 = (120) 1/5 = 2.605 . Write the program so that a user is requested for a positive integer and program prints the series geometric mean of the integer.

Example execution:

Enter number: 5
series geometric mean of 5  = 2.605 
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the simple python program to find the gm

=========================================================================================

def sgm(n):
    product=1
    for i in range(1,n+1):
        product=i*product
    return product**(1.0/n)

n=int(input('Enter number: '))
print('Series geometric mean of {0} = {1}'.format(n,round(sgm(n),3)))

=========================================================================================

Add a comment
Know the answer?
Add Answer to:
Using python Write a Python function called sgm that requests a positive integer n and returns...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • IN PYTHON: Write a function that takes, as an argument, a positive integer n, and returns...

    IN PYTHON: Write a function that takes, as an argument, a positive integer n, and returns a LIST consisting of all of the digits of n (as integers) in the same order. Name this function intToList(n). For example, intToList(123) should return the list [1,2,3].

  • IN PYTHON Write a function called printDigits() that requests the user to input a four-digit integer...

    IN PYTHON Write a function called printDigits() that requests the user to input a four-digit integer and prints the digits using math function, as shown below. You are not allowed to process the number as a string. You must process the number using standard arithmetic operators (+, *, /, %, etc.) >>> printDigits() Enter n: 1234 1 2 3 4 >>> printDigits() Enter n: 9876 9 8 7 6 >>>

  • DONE IN PYTHON The factorial of a non-negative integer n, denoted by n!, is the product...

    DONE IN PYTHON The factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example, 5 ! = 5 × 4 × 3 × 2 × 1 = 120. The value of 0! is 1. Write a program, with comments, to do the following: 20 points Ask the user to enter a positive integer n. between 1 and 20 ; You may assume the user will enter...

  • In Python, write a program that asks the user for a positive integer number. If the...

    In Python, write a program that asks the user for a positive integer number. If the user enters anything else, the program would ask the user to re-enter a number or enter -1 to quit. If it is a positive number, the program then prints out a multiplication table that goes up to that number. For example, if the user enters 10, the output would look something like this. https://www.vectorstock.com/royalty-free-vector/multiplication-table-on-white-background-vector-2721686

  • PYTHON Implement a function called firstAndLast() that requests a nonempty list from the user and prints...

    PYTHON Implement a function called firstAndLast() that requests a nonempty list from the user and prints the first and last items in the list to the screen with the following messages: >>> firstAndLast() Enter a list: [1,2,3,4,5] The first list element is 1 The last list element is 5 >>> firstAndLast() Enter a list: [[1,2,3], [4,5,6], [7,8,9]] The first list element is [1, 2, 3] The last list element is [7, 8, 9]

  • Write a program that reads an integer greater or equal to 2, n, and prints a...

    Write a program that reads an integer greater or equal to 2, n, and prints a shape of a nline hollow inverted pyramid of stars. Your program should interact with the user exactly as it shows in the following two executions: Execution example 1: Please enter an integer, greater or equal to 2: 5 ********* -*----- * --*--- * ---*--* ----* Execution example 2: Please enter an integer, greater or equal to 2: 3 ***** -* * --*

  • Using Python, write a function recur, which on input a positive integer n retuns the value...

    Using Python, write a function recur, which on input a positive integer n retuns the value Bn defined as follows. You can assume that the function is only called with positive integer arguments. B1 = 5, B2​ = 4 B2​ = Bn-1​* Bn-2​ if n is divisible by 3 B3​ = Bn-1​ + Bn-2​ otherwise *Please go step by step with explanation*

  • PYTHON: (Sum the digits in an integer using recursion) Write a recursive function that computes the...

    PYTHON: (Sum the digits in an integer using recursion) Write a recursive function that computes the sum of the digits in an integer. Use the following function header: def sumDigits(n): For example, sumDigits(234) returns 9. Write a test program that prompts the user to enter an integer and displays the sum of its digits. Sample Run Enter an integer: 231498 The sum of digits in 231498 is 27

  • How to solve it using Python? 5. Write a function called no_squares which takes an input...

    How to solve it using Python? 5. Write a function called no_squares which takes an input parameter N, a positive integer, and returns: 1 if N is not divisible by a square and has an even number of prime factors -1 if N is not divisible by a square and has an odd number of prime factors 0 if N is divisible by a square For example, no-squares (10) returns 1 (since 10 = 2x5), no-squares (30) returns-1 (since 30...

  • Write a Python function binom_product that takes integer arguments a and b and positive integer argument...

    Write a Python function binom_product that takes integer arguments a and b and positive integer argument n and returns the product of the coefficients in the expansion of (ax + by)”. Example: Let a = 2, b = -1, and n = 3. Then (2x – y)3 = 8x3 – 12x²y + 6xy2 – 43 The product of the expansion coefficients is 8 x -12 x 6 x -1 = 576 Notes: There are two visible test cases and three...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT