I’ve been struggling with the Python Code Challenge: Functions exercise.

Finally, broke some ground today.

- Write a function named tenth_power( ) that has one parameter named num.

The function should return num raised to the 10th power.

def tenth_power(num):

(two spaces indentation) return num ** 10

print(tenth_power(1))

print(tenth_power(0))

print(tenth_power(2))

Output:

1

0

1024

- Write a function named square_root( ) that has one parameter named num.

Use exponents (**) to return the square root of num.

def square_root(num):

(two spaces inedentation) return num ** (1/2)

print(square_root(16))

print(square_root(100))

Output:

4.0

10.0

1 Like

Did you have a question, or were you just sharing your project’s code?

Hey.

Sharing my code I guess.

Wanting to keep my correct answers saved somewhere lol

- Average

Write a function named average( ) that has two parameters named num1 and num2.

The function should return the average of these two numbers.

def average(num1, num2):

(two spaces indentation) return ((num1 + num2) / 2)

print(average(1, 100))

# The average of 1 and 100 is 50.5

print(average(1, -1))

# The average of 1 and -1 is 0

Output

50.5

0.0

- Remainder

Write a function named remainder( ) that has two parameters named num1 and num2.

The function should return the remainder of twice num1 divided by half of num2.

def remainder(num1, num2):

(two spaces indentation) return (num1 * 2) % (num2 / 2)

print(remainder(15, 14))

print(remainder(9, 6))

Output

2.0

0.0