Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3. Compose a function display_fo fuards that accepts a single positive integer (x) as an argument, and prints all integers on the interval [1, x

image text in transcribed
image text in transcribed
image text in transcribed
3. Compose a function display_fo fuards that accepts a single positive integer (x) as an argument, and prints all integers on the interval [1, x ) in ascending order, each on its own line. If the argument is not a positive integer, the function should print nothing inot even a blank linel. For example. display_forwards (10) * output (via print): \# 1 \# 2 H. 3 H 4 \# 4 (4 7 * 9 display_forwards (5) \# (no text should be displayed) 4. Compose a function display_even_forwards that accepts a single positive integer (x) as an argument, and prints all even integers on the interval (1,x) in ascending order, each on its own line. If the argument is not a positive integec, the function should print nothing (not even a blank line). For example. display_even_fonwards (16) * output (via print): \# 2 \& 4 display_even_fonsards (5) N (no text shoutd be displayed) 5. Compose a function num_yr's that accepts a single numerical argument: the initial deposit amount. This argument should be a positive floating point number. If the argument is zero-or negative, the output of the function is undefined, but the function must return some result after a finite amount of time. If the argument is valid, then the function should return the number of years that would be required for the investment to grow to a total of at least $10,000, with an interest rate of 5% compounded annually. You should solve this problem using a loop to simulate the accrual of interest, stopping when the target amount has been exceeded. As a few examples, \( \begin{array}{lll}\text { nun_yrs (16e) } & \text { W output: } 95 \\ \text { nue_yrs(150eee) } & \text { output: } 0 \\ \text { nun_yrs }(-12) & \text { o output: undefined (but must return *something*) } \\ \text { nue_yrs(0) } & \text { W output: undefined (but must return *somethinge) }\end{array} \) You are NOT allowed to use the following constructs unless specified in the assignment directions. Using the following constructs will result in 0 (zero) for the entire submission (assignment, timed test, etc.). The restricted items are as follows: - Concepts not discussed in lectures yet - String functions - Member functions - Exceptions (can use) : len () and x=x+[y1,y2,y3] - Built-in functions \& types - Exceptions (can use): str(), readline(), open(), close(), write(), read(), range(), split() - Cannot use .append, sort, etc. - Cannot use "Slicing" - Cannot use "list comprehension" - Cannot use "not in" (together) - Cannot use "in" - not allowed with conditionals - Exception (can use): with range () - Cannot use " and \{\} - Exception (can use): mathematical operations (multiply \& exponents) - Data type functions - Exceptions (can use): int(), str (), float () - Break - Continue - Nested Constructs - Exceptions (can use): 2-D list - Multiple returns \& Multiple assignments - Recursion (not allowed unless the question explicitly states otherwise) - Functions within functions (Definitions) -- invocation is fine - Default Parameters - Global variables - Keyword as variable names

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_2

Step: 3

blur-text-image_3

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

Samsung Galaxy S23 Ultra Comprehensive User Manual

Authors: Leo Scott

1st Edition

B0BVPBJK5Q, 979-8377286455

More Books

Students also viewed these Databases questions