Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

f(x) = 2*x count = srange(0,10) vals = [3] for i in count: a = vals[i] b = f(a) vals.append(b) list_plot(vals) Make the above script

f(x) = 2*x

count = srange(0,10)

vals = [3]

for i in count:

a = vals[i]

b = f(a)

vals.append(b)

list_plot(vals)

  1. Make the above script a function called iterate. This function should take no inputs (yes, this is OK) and return the list of values. Test your function. HINT: The header of a function that takes no inputs should have the form def my_function_name():
  2. Copy and modify your iterate function so that the number of times the iteration should be performed is an input. (Use a descriptive name.) Test your function with several different input values. HINT: Where does this number appear in the example?
  3. Copy and modify the previous version of your iterate function so that the initial value is also an input. As before, test your function with several different input values.
  4. Copy and modify the previous version of your iterate function so that the function to be iterated is also an input. Test iterate with at least two different functions. HINT: What line of code will you need to remove when modifying the previous version of the function?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Android 4 Application Development

Authors: Reto Meier

3rd Edition

1118223853, 9781118223857

More Books

Students also viewed these Programming questions