10,434 views
15 votes
15 votes
The function below takes one parameter: an integer (begin). Complete the function so that it prints the numbers starting at begin down to 1, each on a separate line. There are two recommended approaches for this: (1) use a for loop over a range statement with a negative step value, or (2) use a while loop, printing and decrementing the value each time. student.py 1 - def countdown_trigger(begin): 2 - for begin in range(begin, 0, -1): 3 print(begin)The function below takes one parameter: a list (argument_list). Complete the function to create a new list containing the first three elements of the given list and return it. You can assume that the provided list always has at least three elements. This can be implemented simply by creating (and returning) a list whose elements are the values at the zero'th, first and second indices of the given list. Alternatively, you can use the list slicing notation. student.py 1 - def make_list_of_first_three(argument_list): 2 WN Ist = argument_list[: 3 ] return IstIn the function below, return the (single) element from the input list input_list which is in the second to last position in the list. Assume that the list is large enough. student.py 1 - def return_second_to_last_element(input_list) :

User Aswath Krishnan
by
2.9k points

1 Answer

28 votes
28 votes

Answer:

The functions in Python are as follows:

#(1) Countdown program

def countdown_trigger(begin):

for i in range(begin,0,-1):

print(i)

#(2) List of 3

def make_list_of_first_three(argument_list):

print(argument_list[:3])

#(3) Second to last

def return_second_to_last_element(input_list):

print(input_list[-2])

Step-by-step explanation:

The countdown function begins here

#(1) Countdown program

This defines the function

def countdown_trigger(begin):

This iterates through the function

for i in range(begin,0,-1):

The prints the list elements

print(i)

The list of 3 function begins here

#(2) List of 3

This defines the function

def make_list_of_first_three(argument_list):

This prints the first 3 elements

print(argument_list[:3])

The second to last function begins here

#(3) Second to last

This defines the function

def return_second_to_last_element(input_list):

The prints to second to last list element

print(input_list[-2])

User David Khourshid
by
3.3k points