question archive Write a Python script, Lab02_03

Write a Python script, Lab02_03

Subject:Computer SciencePrice:2.85 Bought3

Write a Python script, Lab02_03.py that does the following: a. Uses a for loop to calculate and display the first 10 powers of 2. b. Uses a while loop to find the first power of 2 greater than 5000. Sample Run: 2 to the power 1 is 2 2 to the power 2 is 4 2 to the power 3 is 8 2 to the power 4 is 16 2 to the power 5 is 32 2 to the power 6 is 64 2 to the power 7 is 128 2 to the power 8 is 256 2 to the power 9 is 512 2 to the power 10 is 1024 First power of 2 > 5000 is 2 to the power 13 which is 8192

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE

Answer Preview

3

a.) code to print first 10 powers of 2

for x in range(1,11):
print ' 2 to the power', x ,'is', pow(2,x)

b.) code to print first power of 2 greater than 5000

i = 1
while pow(2,i) < 5000:
i += 1

print 'First power of 2 > 5000 is 2 to the power', i , 'which is', pow(2,i)