Python: How to countdown a number, and append that countdown to a list -
here's effort @ creating countdown in numbers appended list.
timeleft = 3 num1 = 24 - timeleft mylist = [] def countdown(): while num1 != 0: num1 -= 1 mylist.append(num1) countdown() this little section of schedule making app i'm making.
instead of using global variables, i'd write countdown function accepts start parameter , returns list this:
def countdown(start): homecoming list(range(start,0,-1)) demo:
timeleft = 3 num1 = 24 - timeleft cd = countdown(num1) print(cd) # [21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1] if want count 0 utilize range(start,-1,-1).
python list append countdown
No comments:
Post a Comment