migrate to git.charlotte.sh
This commit is contained in:
commit
fbd588721e
412 changed files with 13750 additions and 0 deletions
21
python-csi160/midterm/part8.py
Normal file
21
python-csi160/midterm/part8.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
'''
|
||||
Do not use AI! You can schedule to try again if you have a bad grade!
|
||||
Write a function named 'countdown' which receives a parameter 'n' and returns a list with the countdown from 'n' to 0
|
||||
both included. If 'n' is less than 0, the function should return an empty list.
|
||||
|
||||
Example:
|
||||
print(countdown(5)) # Output: [5, 4, 3, 2, 1, 0]
|
||||
print(countdown(0)) # Output: [0]
|
||||
print(countdown(-1)) # Output: []
|
||||
print(countdown(10)) # Output: [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
|
||||
'''
|
||||
def countdown(n):
|
||||
lst = []
|
||||
for i in range(n, -1, -1):
|
||||
lst.append(i)
|
||||
return lst
|
||||
|
||||
print(countdown(5)) # Output: [5, 4, 3, 2, 1, 0]
|
||||
print(countdown(0)) # Output: [0]
|
||||
print(countdown(-1)) # Output: []
|
||||
print(countdown(10)) # Output: [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
|
Loading…
Add table
Add a link
Reference in a new issue