Let’s Get Functional | CyberStart Completion

Let's Get Functional

Briefing:

You may be thinking by now that programming means typing and retyping lots of things all the time, but actually there’s a handy way we can reuse some of the code you’re writing so you don’t have to do that. They’re called functions and they’re simply little blocks of code that we can call on again and again to do useful things without writing duplicate code.

Hint:

Remember, a function doesn’t necessarily return something.

Code Solution:

The following code is the solution to this challenge. Please note that there may be alternative ways to complete this challenge.


# CHALLENGE 1: Write a function that takes in two integers and
#              multiplies them together then returns the result.
def multiplyTwoInts(int1, int2):
  return int1 * int2
# CHALLENGE 2: Run the function from CHALLENGE 1, passing in the
#              integers 99 and 52 and print the result.
print(multiplyTwoInts(99, 52))

# CHALLENGE 3: Write a function that takes two integers and prints
#              the string "I am X ft Y inches tall", replacing the
#              X and Y with the numbers passed into the function.
def printTwoInts(int1, int2):
  return "I am " + str(int1) + " ft " + str(int2) + " inches tall"

# CHALLENGE 4: Run the function from CHALLENGE 3, passing in 6 and 2
#              as the parameters.

# You should end up with 2 lines output from these 4 challenges.
print(printTwoInts(6, 2))