Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code isnt working
#5
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
Reply


Messages In This Thread
Code isnt working - by abdullahali - Sep-28-2018, 02:25 AM
RE: Code isnt working - by buran - Sep-28-2018, 04:46 AM
RE: Code isnt working - by Skaperen - Sep-28-2018, 05:09 AM
RE: Code isnt working - by ichabod801 - Sep-28-2018, 12:01 PM
RE: Code isnt working - by gruntfutuk - Sep-29-2018, 09:34 AM
RE: Code isnt working - by Skaperen - Oct-01-2018, 02:31 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Getting my choices to display fro some reason it isnt working. dgizzly 5 1,433 Oct-24-2022, 04:53 PM
Last Post: DeaD_EyE
  Python code not working garvind25 1 2,825 Jun-24-2020, 09:38 PM
Last Post: Yoriz
  Please help me get this code working that i haven't posted yet damnit 3 2,523 May-22-2019, 09:57 PM
Last Post: Yoriz
  Homework Teacher isnt helping need some help randyearthchild 2 2,964 Nov-05-2017, 11:32 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020