Write a program using a for loop, that calculates exponentials. Your program should ask for base and exp. value from user.
Answers
Using a for loop, write a program that prints out the decimal equivalents of 1/2, 1/3, 1/4,..., 1/10. negative numbers, what will your program do?) base and an exponent exp, and calculate baseexp.base = float(input('Enter Num:')) exponent = int(input('Enter Exponent:') #what if I want non integer exponent answer = 1 if exponent != 0: #if the exponent is 0 the answer is 1 for in range(abs(exponent)): answer*=base if exponent < 0: answer = 1/answer print('Answer:', answer)
base = float(input('Enter Num:')) exponent = int(input('Enter Exponent:') #what if I want non integer exponent answer = 1 if exponent != 0: #if the exponent is 0 the answer is 1 for in range(abs(exponent)): answer*=base if exponent < 0: answer = 1/answer print('Answer:', answer)5**4 is probably the easiest way. Multiplying as many times as the exponent works only if the exponent is an integer. We can make use of logarithm e.g. a^b is equivalent to exp(b*log a) code is now straight forward.
base = float(input('Enter Num:')) exponent = int(input('Enter Exponent:') #what if I want non integer exponent answer = 1 if exponent != 0: #if the exponent is 0 the answer is 1 for in range(abs(exponent)): answer*=base if exponent < 0: answer = 1/answer print('Answer:', answer)5**4 is probably the easiest way. Multiplying as many times as the exponent works only if the exponent is an integer. We can make use of logarithm e.g. a^b is equivalent to exp(b*log a) code is now straight forward.import math base = 5 exponent = 4 print(math.exp(exponent*math.log(base)))
base = float(input('Enter Num:')) exponent = int(input('Enter Exponent:') #what if I want non integer exponent answer = 1 if exponent != 0: #if the exponent is 0 the answer is 1 for in range(abs(exponent)): answer*=base if exponent < 0: answer = 1/answer print('Answer:', answer)5**4 is probably the easiest way. Multiplying as many times as the exponent works only if the exponent is an integer. We can make use of logarithm e.g. a^b is equivalent to exp(b*log a) code is now straight forward.import math base = 5 exponent = 4 print(math.exp(exponent*math.log(base))) 624.9999999999998 is the answer
Python program using a for loop, that calculates exponentials
Answer:
CODE
base = int(input(" Please Enter the base value : "))
exponent = int(input(" Please Enter Exponent Value : "))
power = 1
for i in range(1, exponent + 1):
power = power * base
print("The Result of {0} Power {1} = {2}".format(base, exponent, power))
OUTPUT:
Please Enter the base value : 2
Please Enter Exponent Value : 3
The Result of 2 Power 3 = 8
ALGORITHM:
1.Start the program.
2. Read the values of the base and exponent
3. set power=1
4.for i in range(1, exponent + 1):
4.1. set power = power * base
5. Print the result
6. Stop the program
TO KNOW MORE ABOUT:
1.Write a Python program to find person is senior citizen or not input page
https://brainly.in/question/12150015
2.A python program to input a single digit number and print its 3 digit number created as (n(n+1)(n+2)). for example if you input 5 then the output should be 567.
https://brainly.in/question/9846913