Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Compose a function called print_lst_even that accepts a single list of integers as an argument. It should print all even elements within the list,

image text in transcribed
image text in transcribed
1. Compose a function called print_lst_even that accepts a single list of integers as an argument. It should print all even elements within the list, each on its own line, in the same order in which they appear within the list. For example, print_1st_even([1, 4,6,7,8,9,10] ) \# output_(via print) \# 4 #6 #8 #8 #10 #10 2. Compose a function called that accepts a single list of integers as an argument. It should print all odd elements within the list, each on its own line, in the same order in which they appear within the list. For example, print_Ist_odd([1, 4, 6, 7, 8,9, 10]) \# output (vla print) #1 #7 #9 #9 3. Compose a function called that accepts a single list of integers as an argument. It should return a new list, containing the square of each even element within the input list, and the cube of each odd element, in the same order in which the elements appear in the input list. The input list should remain unchanged following the function call. For example, \[ \text { 1st_odd_even }([1,4,6,7,8,9,10]) \text { o output: }[1,16,36,343,64,729 \text {, 100] } \] 4. Compose a function called str_len that accepts a single list of strings as an argument. It should return the string from the input list having the longest length, or an empty string ("") if the list is empty. If there are several strings with the longest length, return the first one from the list. hint: you can use the function on strings to get their length. For example, str_len(["hel1o", "world", "abe", "123", "other stuff"]) " output: "other stuff" str_len([]) " output: " 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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 3 Lnai 6323

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

3642159389, 978-3642159381

More Books

Students also viewed these Databases questions

Question

What are the jobs responsibilities and duties?

Answered: 1 week ago