Репост из: 🐹 Hamster Kombat Mini Game
Write the output of the following functions.
A function to add two numbers:
def add_numbers(a, b):
return a + b
result = add_numbers(5, 3)
print(result)
2. A function to check if a number is even:
def is_even(num):
if num % 2 == 0:
return True
else:
return False
print(is_even(4))
print(is_even(5))
3. A function to calculate the area of a circle:
import math
def area_of_circle(radius):
return math.pi * radius ** 2
print(area_of_circle(5))
4. A function to print a greeting message:
def greet(name):
print("Hello, " + name + "!")
greet("Alice")
greet("Bob")
5. A function to calculate the factorial of a number:
def factorial(num):
if num == 0:
return 1
else:
return num * factorial(num-1)
print(factorial(5))
@oroscholarly
Website: oroscholarly.gaammeemedia.com
A function to add two numbers:
def add_numbers(a, b):
return a + b
result = add_numbers(5, 3)
print(result)
2. A function to check if a number is even:
def is_even(num):
if num % 2 == 0:
return True
else:
return False
print(is_even(4))
print(is_even(5))
3. A function to calculate the area of a circle:
import math
def area_of_circle(radius):
return math.pi * radius ** 2
print(area_of_circle(5))
4. A function to print a greeting message:
def greet(name):
print("Hello, " + name + "!")
greet("Alice")
greet("Bob")
5. A function to calculate the factorial of a number:
def factorial(num):
if num == 0:
return 1
else:
return num * factorial(num-1)
print(factorial(5))
@oroscholarly
Website: oroscholarly.gaammeemedia.com