Question

***PYTHON 3*** We are going to practice building some simple lists. Create a function called create_list....

***PYTHON 3***

We are going to practice building some simple lists. Create a function called create_list. It takes 2 parameters, start and end both are integers. This function should return a list that contains all the numbers from start, to end inclusive. So you'll need a loop to count and just append that number into your list and return it. (5 pts )

lst = create_list(5, 10)

lst would be [5, 6, 7, 8, 9, 10]

It should be able to go backwards too.

lst = create_list(10, 5)

lst would be [10, 9, 8, 7, 6, 5]
DON'T FORGET TO GIVE YOUR FUNCTION A DOCSTRING.( 1 pt )

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def create_list(start, end):
    if start <= end:
        lst = []
        i = start
        while i <= end:
            lst.append(i)
            i += 1
    else:
        lst = []
        i = start
        while i >= end:
            lst.append(i)
            i -= 1
    return lst


print(create_list(5, 10))
print(create_list(10, 5))

Add a comment
Know the answer?
Add Answer to:
***PYTHON 3*** We are going to practice building some simple lists. Create a function called create_list....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. use python List to Dictionary Write a function that has three parameters: a list of...

    1. use python List to Dictionary Write a function that has three parameters: a list of unsorted numbers with no duplicates, a start number, and an end number. This function should return a dictionary with all integers between the start and end number (inclusive) as the keys and their respective indices in the list as the value. If the integer is not in the list, the corresponding value would be None. Example unsorted list: [2,1,10,0,4,3] two numbers: 3, 10 returned...

  • In PYTHON! Exercise 3: Lists and Functions In this exercise we will explore the use of...

    In PYTHON! Exercise 3: Lists and Functions In this exercise we will explore the use of lists and functions with multiple inputs and multiple outputs. Your task is to implement the separate_and_sort function. This function takes two input parameters: 1. A list containing strings and integers in any order. 2. An optional integer parameter size which controls how many items in the list the function will process. If the length of the list is smaller than the value of size,...

  • Using PyCharm, under lab8, under Directory exercise, create a Python file called more_loops.py. Write a function,...

    Using PyCharm, under lab8, under Directory exercise, create a Python file called more_loops.py. Write a function, nbrs_greater that accepts 2 integer lists as a parameters, and returns a list of integers that indicates how many integers in the second list are greater than each integer in the first list. For example: nbrs_greater([3, 4, 1, 2, 7], [10, 1, 4, 2, 5, 3]) returns [3, 2, 5, 4, 1] because: Number of numbers in Element of first list Numbers greater from...

  • Python 1 Write a function called sum_odd that takes two parameters, then calculates and returns the...

    Python 1 Write a function called sum_odd that takes two parameters, then calculates and returns the sum of the odd numbers between the two given integers. The sum should include the two given integers, if they are odd. You can assume the arguments will always be positive integers, and the first smaller than or equal to the second. 3 To get full credit on this problem, you must define at least 1 function, use at least 1 loop, and use...

  • Please use Python 3, thank you~ Write a program that: Defines a function called find_item_in_grid, as...

    Please use Python 3, thank you~ Write a program that: Defines a function called find_item_in_grid, as described below. Calls the function find_item_in_grid and prints the result. The find_item_in_grid function should have one parameter, which it should assume is a list of lists (a 2D list). The function should ask the user for a row number and a column number. It should return (not print) the item in the 2D list at the row and column specified by the user. The...

  • PYTHON The first function you will write should be called ‘countDown’. Your function should take zero...

    PYTHON The first function you will write should be called ‘countDown’. Your function should take zero (0) arguments. The function should return one (1) list containing integers from 10 to 1 and finally, the string “Liftoff!”. (i.e., [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, ‘Liftoff!’]). You function must be recursive (i.e., it should contain a call to itself within the function body). You will get NO credit if you use any loops (for, while, etc). 3. Function...

  • IN PYTHON: Write a function that takes, as arguments, two lists, one of which is a...

    IN PYTHON: Write a function that takes, as arguments, two lists, one of which is a character list and the other is the corresponding frequencies, and sorts the characters in ascending order of frequencies. The function should return a list consististing of two lists: the first list is the list of characters and the second is the list of corresponding frequencies, consistent with the rearranged characters. Name this function sortCharacters(characterList, frequencyList). For example, >>>sortCharacters(["a", "b", "c", "d"], [5, 8, 3,...

  • ANSWER USING PYTHON Write a recursive function that takes 2 sorted lists as arguments and returns...

    ANSWER USING PYTHON Write a recursive function that takes 2 sorted lists as arguments and returns a single, merged sorted list as a result. For example, if the two input lists are [0, 2, 4, 6, 8] and [1, 3, 5, 7, 9], the returned result should be [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]. Remember that you can add lists in Python using the + operator ([0] + [1,2,3] = [0,1,2,3]) and can take slices of...

  • In Python and in one file please. (Simple functions with an expressions) Create a function called...

    In Python and in one file please. (Simple functions with an expressions) Create a function called load_inventory(filename). The filename argument in this case specifies the name of a file that contains all the inventory/product information for the store, including product names, descriptions, prices, and stock levels. This function should clear any information already in the product list (i.e., a fresh start) and then re-initialize the product list using the file specified by the filename argument. You can structure your file...

  • Define a function called collapse() which takes a list as input. Each element of the list...

    Define a function called collapse() which takes a list as input. Each element of the list will either be an integer, or a list of integers. The function should modify the input list by replacing all of the elements which themselves are lists with the sum of their elements. For example: Test Result vals = [1, 2, 3, 4, 5] collapse(vals) print(vals) [1, 2, 3, 4, 5] vals = [1, [2, 3], 4, 5] collapse(vals) print(vals) [1, 5, 4, 5]...

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