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 rectangle_area(base, height): | |
| z = base*height # the area is base*height | |
| print("The area is " + str(z)) | |
| rectangle_area(5,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
| # 1) Complete the function to return the result of the conversion | |
| def convert_distance(miles): | |
| km = miles * 1.6 # approximately 1.6 km in 1 mile | |
| return km | |
| my_trip_miles = 55 | |
| # 2) Convert my_trip_miles to kilometers by calling the function above | |
| my_trip_km = convert_distance(my_trip_miles) | |
| # 3) Fill in the blank to print the result of the conversion |
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
| # This function compares two numbers and returns them | |
| # in increasing order. | |
| def order_numbers(number1, number2): | |
| if number2 > number1: | |
| return number1, number2 | |
| else: | |
| return number2, number1 | |
| # 1) Fill in the blanks so the print statement displays the result | |
| # of the function call |
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 lucky_number(name): | |
| number = len(name) * 9 | |
| print("Hello " + name + ". Your lucky number is " + str(number)) | |
| (lucky_number("Kay")) | |
| (lucky_number("Cameron")) |
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 greeting(name): | |
| if name == "Taylor": | |
| return "Welcome back Taylor!" | |
| else: | |
| return "Hello there, " + name | |
| print(greeting("Taylor")) | |
| print(greeting("John")) |
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_storage(filesize): | |
| block_size = 4096 | |
| # Use floor division to calculate how many blocks are fully occupied | |
| full_blocks = filesize//4096 | |
| # Use the modulo operator to check whether there's any remainder | |
| partial_block_remainder = filesize%4096 | |
| # Depending on whether there's a remainder or not, return | |
| # the total number of bytes required to allocate enough blocks | |
| # to store your data. | |
| if partial_block_remainder > 0: |
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 color_translator(color): | |
| if color == "red": | |
| hex_color = "#ff0000" | |
| elif color == "green": | |
| hex_color = "#00ff00" | |
| elif color == "blue": | |
| hex_color = "#0000ff" | |
| else: | |
| hex_color = "unknown" | |
| return hex_color |
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 exam_grade(score): | |
| if score > 95: | |
| grade = "Top Score" | |
| elif score >= 60: | |
| grade = "Pass" | |
| else: | |
| grade = "Fail" | |
| return grade | |
| print(exam_grade(65)) # Should be Pass |
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 format_name(first_name, last_name): | |
| # code goes here | |
| if first_name != '' and last_name != '': | |
| return ("Name: " + last_name + ", " + first_name) | |
| elif first_name != '' or last_name != '': | |
| return ("Name: " + last_name + first_name) | |
| else: | |
| return '' | |
| print(format_name("Ernest", "Hemingway")) |
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 longest_word(word1, word2, word3): | |
| if len(word1) >= len(word2) and len(word1) >= len(word3): | |
| word = word1 | |
| elif len(word2) >+ len(word1) and len(word2) >= len(word3): | |
| word = word2 | |
| else: | |
| word = word3 | |
| return(word) | |
| print(longest_word("chair", "couch", "table")) |