Tuesday, July 23, 2019

Intermediate powers of a set of integers

Script

#!/usr/local/bin/python3.4
import time

maxPower = 8

maxCount = 4

def pwr(number):

        product = 1
        for n in range(1, maxPower + 1):
                product = product * number
                print (number, 'to the power', n, 'equals', product)
                time.sleep(1)

for number in range(1, maxCount + 1):

        pwr(number)
        print ('------------------------------------------------')



Execution

1 to the power 1 equals 1
1 to the power 2 equals 1
1 to the power 3 equals 1
1 to the power 4 equals 1
1 to the power 5 equals 1
1 to the power 6 equals 1
1 to the power 7 equals 1
1 to the power 8 equals 1
------------------------------------------------
2 to the power 1 equals 2
2 to the power 2 equals 4
2 to the power 3 equals 8
2 to the power 4 equals 16
2 to the power 5 equals 32
2 to the power 6 equals 64
2 to the power 7 equals 128
2 to the power 8 equals 256
------------------------------------------------
3 to the power 1 equals 3
3 to the power 2 equals 9
3 to the power 3 equals 27
3 to the power 4 equals 81
3 to the power 5 equals 243
3 to the power 6 equals 729
3 to the power 7 equals 2187
3 to the power 8 equals 6561
------------------------------------------------
4 to the power 1 equals 4
4 to the power 2 equals 16
4 to the power 3 equals 64
4 to the power 4 equals 256
4 to the power 5 equals 1024
4 to the power 6 equals 4096
4 to the power 7 equals 16384
4 to the power 8 equals 65536

------------------------------------------------

No comments:

Post a Comment