Answer to Question #187382 in Python for Kofi

Question #187382
1.Use a for loop and the list append method to generate the powers of 2 to produce the following result [1, 2, 4, 8, 16, 32, 64, 128]
2.Write a for loop that prints a dictionary's items in sorted (ascending) order
1
Expert's answer
2021-05-01T14:11:54-0400
def power_of_2(n=8):


	power_2 = list()
	for i in range(n):
		power_2.append(2**i)
	return power_2


def print_dict(dict_1):


	for el in sorted(dict_1.values()):
		print(el)




print(power_of_2())
print_dict({1: 1, 2: 9, 3: 4})

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS