# Which mathematical operator is used to raise 5 to the second power in python?

1 vote
1.3k views

## Problem:

For the code below I can not get the correct answer:

``````square = 5

results = list(map(lambda a: 5 * a, range(square)))

for i in range(square):
print("5 raised to the power of",i,"is",results[i])``````

This code gives the following output:

``````5 raised to the power of 0 is 0
5 raised to the power of 1 is 5
5 raised to the power of 2 is 10
5 raised to the power of 3 is 15
5 raised to the power of 4 is 20``````

The code is not giving me the actual result. If 5 raised to the power of 2 it should be 25 but the output is showing 10.

What is the problem in my code can anyone sort out?

1 vote

## Solution:

In python to raise a number to the power of another number, you need to use the "**" operator. Where multiplying two numbers only uses one * symbol, the operator for raising one number to the power of another uses two: **.

What you did is you just multiplied the number thats why you are getting this type of results. So your code should be:

``````square = 5

results = list(map(lambda a: 5 ** a, range(square)))

for i in range(square):
print("5 raised to the power of",i,"is",results[i])``````

And you should get the output:

``````5 raised to the power of 0 is 1
5 raised to the power of 1 is 5
5 raised to the power of 2 is 25
5 raised to the power of 3 is 125
5 raised to the power of 4 is 625``````

Happy coding.

## Related questions

3 views
Problem : Need your help to solve this >'how to raise a number to a power in python' ?
15 views
Problem: Any ideas on what I need to do to fix this? Thanks!
1 vote
38 views
Problem: Hello all, I am a new python developer. I don&rsquo;t know if it would be fair to call me a developer because I&rsquo;ve just entered the programming world. I&rsquo;ve joined an online course. Besides that, I am having YouTube lessons and many online guides to ... this. Is there any better option that you can introduce to me? I&rsquo;d love to grab your tips. Thanks for your kind help.
1 vote
12 views
Problem: Any ideas on what I need to do to fix this? Thanks! which operator is used by java runtime implementation to free the memory of an object
95 views
Problem: Hello! I tried running following program: class Program { static void Main(string[] args) { int x = 9; while (x++ < 10) Console.WriteLine(x); Console.ReadKey(); } } The output that I assumed was nothing but a blank screen because x++ = 9 ... 10 I am unable to understand the output. I want to know how that output was generated and in what manner the conditions and operators are evaluated.
159 views
Problem: Is there any way to retrieve a column that matches a certain pattern in SQL? If yes, how can it be done? Explanation with an example would be much appreciated. Thanks!
36 views
Problem: I have a database and I want to retrieve the records that come under a range of values. How can I do that? Is there any mechanism in SQL to do such a thing? If yes, please explain with examples because I am a beginner. Thanks!