PYTHON Write a function named powerI which takes two argumen

PYTHON...

Write a function named powerI which takes two arguments a and b and returns us a raised to the b power.

For this function, you cannot use the ** operator. All other operator are allowed.

Solution

//Tested on ubuntu,Linux

python --version 2.7.12

PLease make sure that code identation while copying the code

/*************power.py***********/

#!/usr/bin/python
#powerI function is taking two parameter a and b
#we are using a for loop and range is b
#and multiplying a upto b time
def powerI(a,b):
   result=1
   for i in range(b):
       result=result*a
   return result

#calling powerI function
res=powerI(2,3)
print \'Result is\', res
  


/**************output*********/

anshu@anshu:~/Desktop/chegg$ python --version
Python 2.7.12
anshu@anshu:~/Desktop/chegg$ python power.py
Result is 8

Thanks a lot

PYTHON... Write a function named powerI which takes two arguments a and b and returns us a raised to the b power. For this function, you cannot use the ** opera

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site