Created
October 21, 2022 04:46
-
-
Save RaMSFT/b91aed6bd20dde553b491a26f6c257fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def stack_boxes(level): | |
#Find the sum of n numbers math formula --> n * (n+1) / 2 | |
sum_of_levels = (level * (level + 1))/2 | |
total_boxes = (2 * (sum_of_levels)) - level | |
return f"Number of boxes for the level: {level} is: {int(total_boxes)}" | |
print(stack_boxes(4)) | |
print(stack_boxes(2)) | |
print(stack_boxes(0)) | |
print(stack_boxes(1)) | |
print(stack_boxes(10)) | |
print(stack_boxes(100)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment