Question

PLEASE USE WHILE LOOP (NOT FOR LOOPS). Python programming. In this problem, you should write one...

PLEASE USE WHILE LOOP (NOT FOR LOOPS). Python programming. In this problem, you should write one function named multiply. This function should accept one parameter, which you can assume will be a list with one or more integers in it. (If you don’t know what I mean when I say “list of integers”, go do the reading!) The function should loop through all of the numbers in the list, and multiply all of the numbers together. It should return the resulting number. For instance, if the parameter was the list [2, 3, 5, 2], the function should return (2 x 3 x 5 x 2) = (6 x 5 x 2) = (30 x 2) = 60. A few examples of arguments and return values are shown below: The function call multiply([20, 4, 3, 7]) should return 1680 The function call multiply([1, 2, 3, 4, 5, 6, 7]) should return 5040 The function call multiply([4, 5, 4, 5, 7, 0, 1, 2, 3]) should return 0 (note the 0 in the argument list) Make sure to include only the one function in your file.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANSWER :

Your code for the above question is written below...

CODE:

def multiply(list1):
    """ calculate product of all items of the list passed"""
    result = 1
    for i in list1:
        result *= i
    return result


# calling the function
print(multiply([2, 3, 5, 2]))
print(multiply([20, 4, 3, 7]))
print(multiply([1, 2, 3, 4, 5, 6, 7]))
print(multiply([4, 5, 4, 5, 7, 0, 1, 2, 3]))

OUTPUT:

THANK YOU......!!!!

Add a comment
Know the answer?
Add Answer to:
PLEASE USE WHILE LOOP (NOT FOR LOOPS). Python programming. In this problem, you should write one...
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
  • PYTHON The first function you will write should be called ‘countDown’. Your function should take zero...

    PYTHON The first function you will write should be called ‘countDown’. Your function should take zero (0) arguments. The function should return one (1) list containing integers from 10 to 1 and finally, the string “Liftoff!”. (i.e., [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, ‘Liftoff!’]). You function must be recursive (i.e., it should contain a call to itself within the function body). You will get NO credit if you use any loops (for, while, etc). 3. Function...

  • Why is it important to initialize the loop control variable for WHILE loops? What does the...

    Why is it important to initialize the loop control variable for WHILE loops? What does the parameter in the function call below do? doStuff(**z); What is the difference between function overloading and Default arguments? Of the two techniques in No. 7, when would you use one over the other?

  • Write a python program (recursive.py) that contains a main() function. The main() should test the following...

    Write a python program (recursive.py) that contains a main() function. The main() should test the following functions by calling each one with several different values. Here are the functions: 1) rprint - Recursive Printing: Design a recursive function that accepts an integer argument, n, and prints the numbers 1 up through n. 2) rmult - Recursive Multiplication: Design a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times...

  • In this problem, you should write one function named copy and increment. This function will have...

    In this problem, you should write one function named copy and increment. This function will have one parameter, which you can assume will be a list of integers. This function should return a copy of the parameter list, in which each number from the parameter list has been increased by 1. The function should not modify the values in the parameter list. For example, the code: values - 20, 40, 10, 60, 77, 2) other copy and incrementales) print values...

  • Please use Python 3, thank you~ Write a program that: Defines a function called find_item_in_grid, as...

    Please use Python 3, thank you~ Write a program that: Defines a function called find_item_in_grid, as described below. Calls the function find_item_in_grid and prints the result. The find_item_in_grid function should have one parameter, which it should assume is a list of lists (a 2D list). The function should ask the user for a row number and a column number. It should return (not print) the item in the 2D list at the row and column specified by the user. The...

  • Using PYTHON (LOOPS, IF STATEMENTS ) I should write a function buckets that  takes two arguments: (bucketCount,...

    Using PYTHON (LOOPS, IF STATEMENTS ) I should write a function buckets that  takes two arguments: (bucketCount, an integer specifying the number of “buckets” to return and numberLs, a list of numbers ) buckets should split the range of values in numberLs into bucketCount sub-ranges. Specifically buckets should return a list-of-lists of length bucketCount. Each list in the returned list-of-lists represents a “bucket”. Each bucket should contain the numbers from numberLs whose values are greater than or equal to min(numberLs) +...

  • PLEASE USE F# PROGRAMMING LANGUAGE: NO LOOPS OR CORE LIBRARY FUNCTIONS. ONLY USE RECURSION. Problem 3...

    PLEASE USE F# PROGRAMMING LANGUAGE: NO LOOPS OR CORE LIBRARY FUNCTIONS. ONLY USE RECURSION. Problem 3 (10 pts) Define a function rev that takes a list xs and returns it in the reverse order. • F# standard library has List.rev, do not use it. You need to reimplement it. In [ ]: let rev (xs: 'a list) In [ ]: // Test you function List.rev [] = rev [] |> printfn "%" List.rev [1..9] = rev [1..9] |> printfn "%b'...

  • Python 1 Write a function called sum_odd that takes two parameters, then calculates and returns the...

    Python 1 Write a function called sum_odd that takes two parameters, then calculates and returns the sum of the odd numbers between the two given integers. The sum should include the two given integers, if they are odd. You can assume the arguments will always be positive integers, and the first smaller than or equal to the second. 3 To get full credit on this problem, you must define at least 1 function, use at least 1 loop, and use...

  • In python please 6 annoying_int_sequence(n) In annoying_recursion.py, write the function annoying_int_sequence(n) which takes a single integer...

    In python please 6 annoying_int_sequence(n) In annoying_recursion.py, write the function annoying_int_sequence(n) which takes a single integer parameter (which must be non-negative). It must return a list of intgers. The contents of the integers are defined recursively. Basically, each version of this sequence is made up of the next-smaller one, repeated n times - and with the number n in-between. For instance, the sequence for n = 3 is: ???? 3 ???? 3 ???? Just drop in the the sequence for...

  • Please code in MatLab or Octave Output should match Sample Output in the second picture Thank...

    Please code in MatLab or Octave Output should match Sample Output in the second picture Thank You 4. In this problem we will investigate using loops to calculate the product of two matrices. Given an mxn matrix A and an n x p matrix B, the matrix product C = AB is the m xp matrix with Cij = R=1 Qikbky. Write a program which calls a function get matrix.dimensions which should • print a description of the purpose of...

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
ADVERTISEMENT