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_fuel(distnace): | |
| """Returns the fuel required for given distance | |
| Args: | |
| distnace (number) | |
| Returns: | |
| number: fuel required is 10 times the distance when it is above 100, else 100 | |
| """ |
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 text_repetition(txt, reps): | |
| """returns repeated text | |
| Args: | |
| txt (string) | |
| reps (number) | |
| Returns: | |
| string: given string is repeated upto given number of times | |
| """ |
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 text_repetition_loop(txt, reps): | |
| """returns repeated text | |
| Args: | |
| txt (string) | |
| reps (number) | |
| Returns: | |
| string: given string is repeated upto given number of times | |
| """ |
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 comp_string_len(str1, str2): | |
| """Compare strings based on the length | |
| Args: | |
| str1 (string) | |
| str2 (string) | |
| Returns: | |
| Boolean: return True if both strings are at same length | |
| """ |
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 and_demo(boolean1, boolean2): | |
| """Demonstrate the and operator using Boolean values | |
| Args: | |
| boolean1 (boolean) | |
| boolean2 (boolean) | |
| Returns: | |
| boolean: returns the result applying and operator | |
| """ |
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 get_sum_of_elements(lst): | |
| return sum(lst) | |
| print(get_sum_of_elements([2, 7, 4])) | |
| print(get_sum_of_elements([45, 3, 0])) | |
| print(get_sum_of_elements([-2, 84, 23])) |
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 get_sum_of_elements_loop(lst): | |
| sum = 0 | |
| for element in lst: | |
| sum = sum + element | |
| return sum | |
| print(get_sum_of_elements_loop([2, 7, 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 convert_to_hms(seconds): | |
| """generate hours:minutes:seconds format from given seconds | |
| Args: | |
| seconds (numeric): number of seconds | |
| Returns: | |
| string: calculate and return the hours, minutes and seconds in H:M:S format | |
| """ | |
| #to get hours, do an integer divison by 3600 to get the hours |
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 difference_max_min(lst): | |
| """Find the difference between largest and smallest numbers from a list | |
| Args: | |
| lst (numerics): a list of numbers | |
| Returns: | |
| number: difference between largest and smallest numbers of the list | |
| """ |
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 find_largest_num_using_for(lst): | |
| """Find the largest number from the list using for loop | |
| Args: | |
| lst (Numeric): a list of numbers | |
| Returns: | |
| Numeric: return the largest of all numbers in the list | |
| """ | |
| # Initiate a variable largest with first element of list |