Project: Overview
- Algorithms course
- Beginner
- Lesson 33/80
- 4 min
Plan a mini app that sorts a price list.
Project: Price sorting
In this project you will build a price-sorting application. You will first define the price array, then add sorting.
Each lesson builds on the previous one and you end up with a working price tool.
Price array
We will store five product prices in an array: [99, 45, 12, 67, 23]. This array is the basis for sorting.
By returning the array from a function, we make it accessible everywhere and the code reusable.
Practice Define price array
Write init_prices(). Return the array [99, 45, 12, 67, 23]. Print it with print(init_prices()).
Starter code
def init_prices():
# Return price arraySample solution
def init_prices():
# Return price array
return [99, 45, 12, 67, 23]
print(init_prices())Expected output
[99, 45, 12, 67, 23]
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Project: Overview: match the terms
| Term | Meaning |
|---|---|
init_prices |
Define array |
sort_prices |
Sort |
print_sorted |
|
average_price |
Average |
2 What is the first step of the project?
- Printing
- Define price array
- Average
- Sorting Correct answer
Explanation: The first step is to define the price array.
3 Array definition
The price array is ____.
The price array is [99, 45, 12, 67, 23].
Explanation: [99, 45, 12, 67, 23] is right.