Posts: 4,655
Threads: 1,498
Joined: Sep 2016
what is your code doing wrong? is it printing out "42" or "foo"?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 232
Threads: 2
Joined: Sep 2017
Assuming you have your indention correct (we can't tell, because you have not put BBCode tags around your code yet), then you are missing a
:
at the end of the if statement line. As mentioned, best not to use things Python already uses as your variable names.
Here's a corrected version of your code, and also an alternative approach, as well as example usage. Note I changed int to int_ to avoid
hiding the int type.
def powerTo(double, int_):
if int_ >= 0:
return double ** int_
else:
return 0
def powerTo2(double, int_):
return 0 if int_ < 0 else double ** int_
for num in range(-2, 4):
print(powerTo(5, num), powerTo2(5, num))
I am trying to help you, really, even if it doesn't always seem that way
Posts: 4,655
Threads: 1,498
Joined: Sep 2016
yeah, show your indentation.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.