Question

In: Computer Science

Write a function in Python 3 (v. 6175+) called multiplicity00794. The function should receive alimit number...

Write a function in Python 3 (v. 6175+) called multiplicity00794. The function should receive alimit number and return:
• how many multiples of 3 or 5 or 7 there are that are less than or equal to the specified limit.
• the sum of the multiples of 3 or 5 or 7 that are less than or equal to the specified limit.
• the product of the multiples of 3 or 5 or 7 that are less than or equal to the specified limit.
For example, if the function is invoked with 15 it should return 9 (because there are 9 multiples of 3, 5 or 7 less than or equal to
than 15: 3, 5, 6, 7, 9, 10, 12, 14 and 15), 81 (because 3 + 5 + 6 + 7 + 9 + 10 + 12 + 14 + 15 = 81) and 142884000 (because
3 * 5 * 6 * 7 * 9 * 10 * 12 * 14 * 15 = 142884000).

Solutions

Expert Solution

Python code:

#defining multiplicity00794 function
def multiplicity00794(limit):
    #initializing count as 0
    count=0
    #initializing total as 0
    total=0
    #initializing product as 1
    product=1
    #looping from 1 to limit
    for i in range(1,limit+1):
        #checking if number is divisible by 3 or 5 or 7
        if(i%3==0 or i%5==0 or i%7==0):
            #incrementing count
            count+=1
            #adding current number to total
            total+=i
            #multiplying current number to product
            product*=i
    #returning count,sum and product
    return(count,total,product)
#calling multiplicity00794 function and printing result
print(multiplicity00794(15))

Screenshot:


Output:


Related Solutions

This is python: #Write a function called count_positive_evens. This function #should take as input a list...
This is python: #Write a function called count_positive_evens. This function #should take as input a list of integers, and return as #output a single integer. The number the function returns #should be the count of numbers from the list that were both #positive and even. # #For example: # # count_positive_evens([5, 7, 9, 8, -1, -2, -3]) -> 1 # count_positive_evens([2, 4, 6, 8, 10, 12, 15]) -> 6 # count_positive_evens([-2, -4, -6, -8, -10, 1]) -> 0 # #0...
PYTHON: Write a function insertInOrder that takes in a list and a number. This function should...
PYTHON: Write a function insertInOrder that takes in a list and a number. This function should assume that the list is already in ascending order. The function should insert the number into the correct position of the list so that the list stays in ascending order. It should modify the list, not build a new list. It does not need to return the list, because it is modifying it.   Hint: Use a whlie loop and list methods lst = [1,3,5,7]...
using python 1. #Write a function called multiply_file_by_index. This function #should take two parameters, both strings....
using python 1. #Write a function called multiply_file_by_index. This function #should take two parameters, both strings. The first string is #the filename of a file to which to write (output_file), and #the second string is the filename of a file from which to read #(input_file). # #In the input file, there will be an integer on every line. #To the output file, you should write the integer from the #original file multiplied by the line number on which it #appeared....
use the python language and fix the error code #Write a function called rabbit_hole. rabbit_hole should...
use the python language and fix the error code #Write a function called rabbit_hole. rabbit_hole should have #two parameters: a dictionary and a string. The string may be #a key to the dictionary. The value associated with that key, #in turn, may be another key to the dictionary. # #Keep looking up the keys until you reach a key that has no #associated value. Then, return that key. # #For example, imagine if you had the following dictionary. #This one...
Python 3 Write the definition of a function that take one number, that represents a temperature...
Python 3 Write the definition of a function that take one number, that represents a temperature in Fahrenheit and prints the equivalent temperature in degrees Celsius. Write the definition of another function that takes one number, that represents speed in miles/hour and prints the equivalent speed in meters/second. Write the definition of a function named main. It takes no input, hence empty parenthesis, and does the following: - prints Enter 1 to convert Fahrenheit temperature to Celsius - prints on...
IN PYTHON Create a function called biochild.  The function has as parameters the number m...
IN PYTHON Create a function called biochild.  The function has as parameters the number m and the lists biomother and biofather.  The biomother and biofather lists contain 0’s and 1’s.  For example: biomother = [1,0,0,1,0,1] and biofather = [1,1,1,0,0,1]  Both lists have the same length n.  The 0's and 1's represent bits of information (remember that a bit is 0 or 1).  The function has to generate a new list (child).  The child...
Using Python 3 Write a function reads the file called simpleinterest.txt. Each row in simpleinterest.txt is...
Using Python 3 Write a function reads the file called simpleinterest.txt. Each row in simpleinterest.txt is a comma seperated list of values in the order of PV, FV, n, r. For each row, there is one value missing. Write an output file that fills in the missing value for each row.
using python 1. #Write a function called multiply_by_index. multiply_by_index #should have one parameter, a list; you...
using python 1. #Write a function called multiply_by_index. multiply_by_index #should have one parameter, a list; you may assume every item #in the list will be an integer. multiply_by_index should #return a list where each number in the original list is #multipled by the index at which it appeared. # #For example: # #multiply_by_index([1, 2, 3, 4, 5]) -> [0, 2, 6, 12, 20] # #In the example above, the numbers 1, 2, 3, 4, and 5 appear #at indices 0,...
a. Write a c++ function called IsPalindrome that receives a 3-digit number and returns whether it...
a. Write a c++ function called IsPalindrome that receives a 3-digit number and returns whether it is palindrome or not. [2.5 marks] b. Write a c++ function, called GCD that receives two parameters n, d, and prints their greatest common divisor [2.5 marks] Now after you created the two functions, you have to write a main function that can call the above functions according to user choice. Write a menu that allows the user to select from the following options...
Write a recursive function in python called make_palindrome that takes a sequence as a parameter and...
Write a recursive function in python called make_palindrome that takes a sequence as a parameter and returns a new sequence that is twice the length of the parameter sequence but that contains the contents of the original in palindrome form. For example, if the sequence "super" is passed into the function, the function will return "superrepus".
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT