# How do you add an exponent function?

Hey all,

I was just coding a calculator for fun in python and I wasn't sure how to add an exponent function. Can anyone help me?

Thanks

**Voters**

Axrevyn

A `while`

loop, I suppose?

`num=int(input("number: ")) exponent=int(input("exponent: ")) ans = num while exponent>1: ans = ans*num exponent = exponent-1 print(str(ans))`

I whipped this up in five minutes, you should probably test it before using it.

IMACODERBOIZ

@Axrevyn

Actually, I searched it up on google and you need to do this pow(base, exponent) in the answer spot. But I think a while loop could work too. BTW, do you wanna work on this calculator together?

Actually, I searched it up on google and you need to do this pow(base, exponent) in the answer spot. But I think a while loop could work too. BTW, do you wanna work on this calculator together?

Axrevyn

@IMACODERBOIZ Revised it

`num=int(input("number: ")) exp=int(input("exponent: ")) ans = num if exp >= 2: while exp>1: ans = ans*num; exp = exp-1 elif exp == 1: pass elif exp == 0: ans = 1 print(str(ans))`

And I realize that there are better ways to do this. Heh.

I'll work with you, why not?

Alright thank you for helping me guys

First, you should mark an answer as correct.

Second, have you checked out the calculator? I fixed and finished the area function. I also left some notes that you should probably look through.

Yes I have checked out the calculator, thanks a lot. But I was wondering what does global choice mean and why did you use it?

`global`

variable makes sure that I'm using theglobalversion, not the function-specific one.Example:

Both of those print the variable

`var`

. However, this code will outputEven though it's printing the same variable. Using

`global`

negates that.