Python Code Challenges: Control Flow

ok, so on the first question regarding “Large Power”
Is someone able to break it down for me? i don’t fully understand how the sytax is written here?
# Write your large_power function here:
def large_power(base, exponent):
** if base ** exponent > 5000:**
** return True**
** else: **
** return False**

# Uncomment these function calls to test your large_power function:
print(large_power(2, 13))
# should print True
print(large_power(2, 12))
# should print False

wouldnt you have to attatch the exponent to either the base or the exponent? I’m not seeing how either of these could possibly be larger than 5000?
when we use the exponent is it safe to assume we’re disregarding the comma in our parameter? so that way it looks more like 2**13? (and 12)

i hope I wrote this properly

In maths, we write the exponent as a superscript of the base. When that is not possible we symbolize it in pseudo form, as base ^ exponent. In Python we replace the carat symbol with the exponent opertor, **.

2 ** 4 == 16
1 Like

The comma in your function’s parameter list is separating them so python knows to expect 2 arguments for this function to execute. Using appropriate names can cause us to assign more meaning to the variable than python does.

def large_power(number_1, number_2):

  if type(number_1) != int or type(number_2) != int:
    print("Function parameters must be integers")
  elif number_1 ** number_2 > 5000:
    return True
    return False

the only thing that makes them base and exponent is in your code. I added some code to check the parameter type to demonstrate.

1 Like