Exponent Function | Python | Tutorial 23

preview_player
Показать описание

Throughout the course we'll be looking at various topics including variables, lists, tuples, loops, conditionals, object orientation, and much more.
Рекомендации по теме
Комментарии
Автор

Here is the same code but now with user input capabilities:

base_num = int(input("Enter the base number: "))
pow_num = int(input("Enter the power number: "))

def raise_to_power(base_num, pow_num):
results = 1
for index in range (pow_num):
results = results * base_num
return results

print(raise_to_power(base_num, pow_num))

ivankeli
Автор

This isn't clear for me, you say result=1, then result*base_num, so isn't that 1* base num. the videos were very easy at first but a since a couple of vids . I'm unable to follow. I can do what u do, but to replicate and create something with it . I'm afraid it's impossible . bec. I just know the specific function u r doing but I don't understand the reason behind it, therefore can't customize to anything diff.
for example if I wanna create an exponential fun. like this vid. I'll just follow your instruction but I can't create any varieties for the (for) function coz I don't really understand here.

fictionaddiction
Автор

Ok, this is cool. But why don't you just say print(base_num ** pow_num) ?

mr_hxid
Автор

I'm going to have to watch all your classes. I'm in python now and for some reason really struggling.
Now on to Fibonacci seguence

anthonylarso
Автор

For some reason I find this function way harder than it needs to be... wouldn't it be better just define a function with 2 parameters, which returns the result without defining a result variable? Like this:

def raise_power(base_num, pow_num):
>>>> return base_num ** pow_num

Now, you could call the function and even define those 2 parameters by user inputs whenever you want...

pepino-cosmico
Автор

Can someone please explain why we are taking result=1 and what will happen if we don’t take result =1

anjaliwadhwani
Автор

Is this okay? tried without including the return thingy and it worked the same.

def expo(baseNum, powNum):
result = pow(baseNum, powNum)
total = print("Exponent of {}^{} is: {}".format(baseNum, powNum, result))
return total


expo(3, 3)

running the program:

Exponent of 3^3 is: 27

Plebku
Автор

The only critique I have for you videos are to add more explanation and more labs. Everything else is great!

VikramSingh-upib
Автор

You're easy to follow and you make things really simple to understand

mbulelogumede
Автор

def raise_to_power(a, b):
c = a**b
return c
Am I wrong :/

paulburg
Автор

Hello, A question: how would look like this example but set in general, given any pair of numbers by the user? thank you!

infundere
Автор

At Exponent Function he used result = 1, then result*base_num, so isn't that 1 * base num. And can someone also briefly explain the use of For Loop. thanks 4 the help

boundball
Автор

easier way to do this is **:

num = int(input('num?'))
power = int(input('power? '))

def math(x, y):
print(x**y)

math(num, power)

mndx
Автор

This exponent function can't work when I try. Why? I am a beginner of programming.

kophyo
Автор

Why wouldn't we use a If/Else to accomplish this? What makes the For Loop a better choice?

andrewneary
Автор

why did we take index in this. and thnx for tutorial really helpful and fun to learn.

pradyumankannan
Автор

what about
def expoo ( base_num, power_num):
return base_num**power_num
print(expoo(3, 2))

ahmedmohsen
Автор

i know this is an old video but if anyone sees this, I just want to know what is the point of putting result = 1? I mean I have been on this specific part of the video for hours now. I cannot wrap my head around it.

Rick-uyoy
Автор

im too confused, someone explain please

praveshmaharaj
Автор

I'm very confusion about why we get a int, rather than a string when we put the number in the def directly?

-xy