Lab 3: Compute power of a number (Exponentiation)
Problem statement
Write a Python program to compute the power of a given number.
Sample Input1: 2,3
Sample Output1: 8
Sample Input2: 0, 3
Sample Output2: 0
Sample Input3: 3,0
Sample Output3: 1
Sample Input4: 2, -3
Sample Output4: 0.125
Sample Input4: 2, "ab"
Sample Output4: Invalid InputSolution Key
Using for loop
for loopUsing while loop:
Using builtin function
Using ** operator:
CD links
http://cyberdojo.kgfsl.com/kata/edit/90A83D4231?avatar=peacock - for loop http://cyberdojo.kgfsl.com/kata/edit/06D7B4092A?avatar=elephant - Builtin func http://cyberdojo.kgfsl.com/kata/edit/06D7B4092A?avatar=bear - using ** operator http://cyberdojo.kgfsl.com/kata/edit/06D7B4092A?avatar=squirrel - while loop
PreviousLab 2: Find the square root of a number (Newton’s method)NextLab 3: Exponentiation (power of a number)
Last updated