Question

This is a python question. Write a function mult_table(n) that consumes a natural number n and...

This is a python question.

Write a function mult_table(n) that consumes a natural number n and returns the n+1 by n+1 multiplication table (where each entry in the inner list is equal to the product of which list it is and the inner list position number, or in other words, the product of the row and column numbers). Using accumulative recursion, no abstract list functions.

def mult_table(n)
'''
Returns the n+1 by n+1 multiplication table
  
mult_table: Nat => (listof (listof Nat))
  
Examples:
mult_table(0) => [[0]]
mult_table(1) => [[0, 0],
[0, 1]]
mult_table(2) => [[0, 0, 0],
[0, 1, 2],
[0, 2, 4]]
mult_table(5) => [[0, 0, 0, 0, 0, 0],
[0, 1, 2, 3, 4, 5],
[0, 2, 4, 6, 8, 10],
[0, 3, 6, 9, 12, 15],
[0, 4, 8, 12, 16, 20],
[0, 5, 10, 15, 20, 25]]
'''

No loops! No abstract list functions! Only accumulative recursion can be used!

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
This is a python question. Write a function mult_table(n) that consumes a natural number n and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • 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...

  • Need help writing these functions in Python: FUNCTION 1 get_course_ids: Consumes a list of Course dictionaries...

    Need help writing these functions in Python: FUNCTION 1 get_course_ids: Consumes a list of Course dictionaries and returns a list of integers representing course IDs. Here's what I have so far but I'm getting a Type Error - list indices must be integers or slices, not dict. def get_course_ids(courses): course_ids = [] for course in courses: course_ids.extend(courses[course])    return course_ids FUNCTION 2 choose_course: Consumes a list of integers representing course IDs and prompts the user to enter a valid ID,...

  • USING PYTHON 3 Write a function no_pairs(L) that consumes a list of natural numbers L and...

    USING PYTHON 3 Write a function no_pairs(L) that consumes a list of natural numbers L and mutates it, replacing any natural numbers which appear exactly twice in the list with -1. The no_pairs function returns None. This function should run in at worst O(n log n) time. HINT: Solving this problem within the demanded runtime will likely require both O(n log n) sorting and O(log n) searching! Samples: L = [254 , 955 , 198 , 590 , 368] after...

  • (Python) (15 points) Fundamental theorem of number theory states that every natural number n can be...

    (Python) (15 points) Fundamental theorem of number theory states that every natural number n can be expressed as a product of prime numbers, called its prime factorization. E.g. 15 3 x 5,20 2x 2x5. You are required to write a Python function prime factors(n) which accepts a natural number as the input argument and returns a list of all the prime factors of n in ascending order. (Use 20, 666, 4020 to test your program.) 2.

  • Python: Write a function subsetSum() that takes as input a list of positive number and a...

    Python: Write a function subsetSum() that takes as input a list of positive number and a positive number target. The function returns True if there are three numbers in the list that add up to the target. For example, the list [5, 4, 10, 20, 15, 19] and targert 38, then True is returned since 4 + 15 + 19 = 38. However, the list [5, 4, 10, 20, 15, 19] and target 5 returns False. >>> subsetSum([5, 4, 10,...

  • 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...

  • The language is python Write the function largest_edge_group(vertices) that consumes vertices, a list of list of...

    The language is python Write the function largest_edge_group(vertices) that consumes vertices, a list of list of integer containing the coordinates of the consecutive vertices of a polygon. The function largest_edge_group returns the size of the largest group of same length edges. Your function must run in O(n), where n is the length of vertices. Example largest_edge_group([[0,0],[1,1],[0,2],[-2,3],[-1,2]]) => 3 Hint Remember, it is not possible to compare Floats for strict equality, but since the coordinates are integers, the squared distance is...

  • Write the function below in scheme/lisp programming language. Drracket Exercise: It is well known that n^2...

    Write the function below in scheme/lisp programming language. Drracket Exercise: It is well known that n^2 is equal to the sum of the first n odd numbers. For example, 16 = 4^2 = 7 + 5 + 3 + 1. Write a function that takes as input a natural number, n, and that returns the square of its input by adding the first n odd numbers. Your code may not contain delayed operations and must use accumulative recursion.

  • Python. Write a function that takes in a list and returns the first nonzero entry. def...

    Python. Write a function that takes in a list and returns the first nonzero entry. def nonzero(lst): """ Returns the first nonzero element of a list >>> nonzero([1, 2, 3]) 1 >>> nonzero([0, 1, 2]) 1 >>> nonzero([0, 0, 0, 0, 0, 0, 5, 0, 6]) 5 """ "*** YOUR CODE HERE ***"

  • Using Python In the decimal system (base 10), a natural number is represented as a sequence...

    Using Python In the decimal system (base 10), a natural number is represented as a sequence dndn?1 . . . d0 of (decimal) digits, each of which is in the range 0..9. The value of the number is d0 ×100 +d1 ×101 +···+ dn ×10n. Similarly, in the binary system (base 2), a natural number is represented as a sequence bnbn?1 · · · b0 of (binary) digits, each of which is 0 or 1. The value of the number...

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