Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,961 questions

51,903 answers

573 users

How to calculate power of a number in Python

4 Answers

0 votes
exponent = 4
n = 2
i = 1
power = 1

while i <= exponent:
    power *= n
    i += 1


print(n, " ^ ", exponent, " = ", power)


'''
run:

2  ^  4  =  16

'''

 



answered May 22, 2017 by avibootz
0 votes
exponent = 4
n = 2

power = pow(n, exponent)

print(n, " ^ ", exponent, " = ", power)


'''
run:

2  ^  4  =  16

'''

 



answered May 22, 2017 by avibootz
0 votes
import math

x = math.pow(2, 4)
print(x)


'''
run:

16.0

'''

 



answered Sep 14, 2018 by avibootz
0 votes
y = 2 ** 4
print(y)


'''
run:

16

'''

 



answered Sep 14, 2018 by avibootz

Related questions

1 answer 185 views
1 answer 52 views
1 answer 114 views
1 answer 115 views
1 answer 112 views
112 views asked Jul 24, 2021 by avibootz
...