Calculate and return the largest value which is a multiple

Assignment Help Computer Engineering
Reference no: EM132212318

Write a recursive function, max_multiples_list(lst, m), which takes an non-empty list, lst, of integers as a parameter and m is also an integer.

This function calculates and returns the largest value which is a multiple of m in the list. 0 is returned if there is no number that is the multiples of m in the list.

The base case will probably deal with the scenario where the list has just one value. The recursive case will probably call the function recursively using the original list, but with one item removed.

Test:

l = [1, 4, 5, 9, 11]
print(max_multiples_list(l, 3))

Result:

9

And there is my code, can anyone give a little help about how can I change my code?

def max_multiples_list(lst,m):
if len(lst)==1:
if lst[0] % m ==0:
return lst[0]
else:
return 0
else:
if lst[0]%m ==0:
return max(lst[0],max_multiples_list(lst[1:]))
else:
return 0

Reference no: EM132212318

Questions Cloud

Compute the velocity of a parachutist exactly and numerical : Write pseudocode for a function that computes the velocity of a parachutist exactly and numerically as a function of time from 0s to 30s using Euler's method.
Record the revaluation of the foreign currency : Assume that Maple used forward contracts to manage the foreign currency risks of all of its export and import transactions during 20X5.
Write a pthreads program that generates multiple threads : Write a Pthreads program in C on Linux that generates multiple threads. The threads should complete in the order below using semaphores.
What are carla fixed costs : Carla sells hot coffee; cider and tea from a sidewalk cart near Wall Street in New York City. Last month she sold $4,500 worth of product to 1,000 customers.
Calculate and return the largest value which is a multiple : Write a recursive function, max_multiples_list(lst, m), which takes an non-empty list, lst, of integers as a parameter and m is also an integer.
Compute the sum of the elements of an integer array : Write a recursive algorithm that computes the sum of the elements of an integer array.
Is what joe considering unethical : You are a CPA and have been hired as a consultant to Brown Corporation's accounting staff and especially to assist Joe. Write a one-page (maximum) memo.
How many times an item appears on a list : Write recursive Dr Racket functions to do the following. The functions should work on all types of lists( not just simple lists of atoms).
Compute the amount of raw materials used during august : Compute the amount of raw materials used during August if $30,000 of raw materials were purchased during the month and the inventories were as follows.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd