L7 2 Buildlistpy Write Program Builds List Numlist Numlist 020 Using Accumulator Pattern I Q37300768

[L7-2](build_list.py) Write a program that builds a listnum_list such that num_list[i] =i for i == 0..20. Do this by using theaccumulator pattern: initialize num_list to theempty list [], then loop over each integer,appending it to the end of num_list. At the end,print out your final value of num_list.

[L7-3](build_list2.py) Same as [L7-4]but build num_list by concatenating thelist [num] to the end of numlist,then assigning the result to num_list. Print outthe final value of num_list as before.

[L7-4] (build_list3.py) Sameas [L7-4], but build num_list by using a listcomprehension: num_list = [num for num inrange(21)].


Answer


L7-2)

num_list = []num=20i = 0for i

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.