05/05/2024
05/05/2024
05/05/2024
Trâmm Bảo
Đây là câu trả lời của mình nè.
05/05/2024
Python
def calculate_power(x, k):
"""
This function calculates the power of a number.
Args:
x: The base number.
k: The exponent.
Returns:
The value of x raised to the power of k.
"""
# Base case: If k is 0, return 1
if k == 0:
return 1
# Recursive case: Otherwise, return x multiplied by itself k times
return x * calculate_power(x, k-1)
# Calculate the power of 2 raised to 3
result_power = calculate_power(2, 3)
# Calculate the sum T = m^3 + n^5 + p^2
m, n, p = 3, 4, 2
result_sum = m**3 + n**5 + p**2
# Print the results
print("Result of power calculation:", result_power)
print("Result of sum calculation:", result_sum)
Nếu bạn muốn hỏi bài tập
Các câu hỏi của bạn luôn được giải đáp dưới 10 phút
CÂU HỎI LIÊN QUAN
Top thành viên trả lời