4/19 What am I doing wrong! Please help


#1

def power(argument 1, argument 2): # Add your parameters here!
result = 37**4
print "%d to the power of %d is %d." % (base, exponent, results)

power(37,4) # Add your arguments here!


#2

Hi @akinsey105,

Here's a little trick:

Whenever you would like to paste code, since this forum supports Markdown you can use three backticks before and after your code block like so:

```
def my_func(x):
my_var = 0
if x > my_var:
sum = my_var + x
else:
print "Odelay!"
return sum
```

and it will retain proper indentation and even have nifty syntax highlighting:

def my_func(x):
    my_var = 0
    if x > my_var:
      sum = my_var + x
    else:
      print "Odelay!"
    return sum

That being said, the problems I see with your code are these two:

  • On line 2, you hardcoded 37 ** 4 as a result. Doing so will always return 37 ** 4 no matter what argument you pass to your function. That is not what we want. Passing 3 and 2 as arguments should return the 3 to the power of 2, not 37 to the power of 4.
  • You need to use the same name you pass as parameters inside your function. You pass argument1 and argument2 but try to refer to them by using the names base and exponents in your functions, names that you have not defined anywhere else before so it will indeed creates an error

Basically what you need to do is something like this:

def product(first_num, sec_num):
    result = first_num * sec_num
    print "%d multiplied by %d is %d." % (first_num, sec_num, result)

product(2,2)    # will return 4 as expected
product(3,2)    # will return 6 also as expected

Hope it helped you! Good luck! :smile: