Skip to content

Latest commit

 

History

History
43 lines (29 loc) · 1.67 KB

File metadata and controls

43 lines (29 loc) · 1.67 KB

Math Power

The problem

Take two numbers from the users. Calculate the result of second number power of the first number.

Hints

To power, you will need to use two asterisks symbols (two multiplication symbols). For example 4 to the power 3 will be

result = 4**3

Solution

base_num = int(input('Give me the base number: '))
power_num = int(input('Give me the power number: '))
result = base_num ** power_num
print('Your result is: ', result)

Try it on Programming Hero

Think Different

Python has a built-in function named pow. The pow is a short form of the word power. And you can pass 2 numbers to the pow function. It will give you the second number as a power of the first number.

Alternative Solution

Python has a built-in function named pow. The pow is a short form of the word power. And you can pass 2 numbers to the pow function. It will give you the second number as a power of the first number.

base_num = int(input('Give me the base number: '))
power_num = int(input('Give me the power number: '))
result = pow(base_num, power_num)
print('Your result is: ', result)

Try it on Programming Hero

  Next Page  

tags: programming-hero python python3 problem-solving programming coding-challenge interview learn-python python-tutorial programming-exercises programming-challenges programming-fundamentals programming-contest python-coding-challenges python-problem-solving