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)) |
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 reverse_list(lst): | |
lst.reverse() | |
return lst | |
print(reverse_list([1, 2, 3, 4])) | |
print(reverse_list([9, 9, 2, 3, 4])) | |
print(reverse_list([])) | |
print(reverse_list([8, 9, 16, 17, 1, 2, 3, 4])) |
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 leapyear(year): | |
if year % 100 == 0: | |
if year % 400 == 0: | |
return f"year: {year} is a leap year" | |
else: | |
return f"year: {year} is not a leap year" | |
else: | |
if year % 4 == 0: | |
return f"year: {year} is a leap year" |
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 front3(str): | |
if len(str) > 3: | |
return str[:3] * 3 | |
else: | |
return str * 3 | |
print(front3("Python")) | |
print(front3("Cucumber")) | |
print(front3("bioshock")) | |
print(front3("Ra")) |
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 check_title_string(str): | |
#Check if the the string is title string or using string method | |
title = str.istitle() | |
return title | |
print(check_title_string("A Mind Boggling Achievement")) |
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 check_title_string_spl(str): | |
#Convert the string to list of words | |
str_list = str.split(' ') | |
#Loop through each word from list of words | |
for word in str_list: | |
#Check if the word start characte is upper or not | |
if not word[0].isupper(): |
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 calculate_with_op(num1, num2, op): | |
equation = f"{num1} {op} {num2}" | |
result = eval(equation) | |
return f"equation: {equation} results: {result}" | |
print(calculate_with_op(4, 9, "+")) |
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 flip_bool(bool): | |
if bool: | |
return 0 | |
else: | |
return 1 | |
print(flip_bool(True)) | |
print(flip_bool(False)) |
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 how_many_walls(paint_area, width, height): | |
area_of_wall = width * height | |
times = paint_area // area_of_wall | |
return times | |
print(how_many_walls(100, 4, 6)) |
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 full_half_quarter_so_on(num): | |
result = [num, num/2, num/4, num/8] | |
return result | |
print(full_half_quarter_so_on(6)) | |
print(full_half_quarter_so_on(22)) | |
print(full_half_quarter_so_on(25)) |