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
"""" | |
Write a function that sums up the multiples of a given number between a given start and end. | |
If the start or end numbers are also multiples, it should include them in the sum. | |
For example, if the range is 1-12 and the divisor is 4, the function should add 4+8+12, returning 24. | |
""" | |
def sum_multiples(start, end, divisor): | |
""" | |
>>> sum_multiples(1, 12, 4) | |
24 |
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
"""Write a function that will count the amount of multiples | |
of a given divisor between a given start number and a given end number. | |
It should include the start or end if they are a multiple. | |
For example, if the range is 1 to 12 and the divisor is 3, | |
the function should return 4, since 3, 6, 9, and 12 can all be evenly divided by 3. | |
""" | |
def count_multiples(start, end, divisor): | |
""" |
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
"""Write a function that will count the number of even numbers between a given start number and a given end number. | |
It should include the start or end if they are even. | |
""" | |
def count_evens(start, end): | |
""" | |
>>> count_evens(2, 2) | |
1 | |
>>> count_evens(-2, 52) | |
28 | |
>>> count_evens(237, 500) |
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 should return the product | |
of all the numbers from 1 to the given end number | |
(including the end number). | |
It is mostly written for you, but it has several bugs! | |
Tips for debugging: | |
* Read through the code and trace it on paper for small inputs | |
* Try running the tests and observe the output | |
* If you have a hunch, try changing the code and seeing how the output changes |
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
""" | |
Write a function named assign_grade that: | |
* takes 1 argument, an integer representing the score. | |
* returns a grade for the score, either "A" (90-100), "B" (80-89), "C" (70-79), "D" (65-69), or "F" (0-64). | |
Call that function for a few different scores and log the result to make sure it works. | |
""" | |
def assign_grade(score): | |
""" | |
>>> assign_grade(95) |
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
""" | |
Write a function named hello_world that: | |
* takes 1 argument, a language code (e.g. "es", "pt", "en") | |
* returns "Hello, World" for the given language | |
It should return English if an invalid language code is specified. | |
""" | |
def hello_world(language_code): | |
""" | |
>>> hello_world("en") | |
'Hello, World' |
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
""" | |
Write a function named lesser_num that: | |
* takes 2 arguments, both numbers. | |
* returns whichever number is the smaller (lesser) number. | |
Use a conditional to implement the function. | |
""" | |
def lesser_num(num1, num2): | |
""" | |
>>> lesser_num(45, 10) | |
10 |
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
""" | |
Write a function named greater_num that: | |
* takes 2 arguments, both numbers. | |
* returns whichever number is the greater (higher) number. | |
Use an if/else to implement the function. | |
""" | |
def greater_num(num1, num2): | |
""" | |
>>> greater_num(45, 10) | |
45 |
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 should return true | |
if the month is July OR the tuber size is at least 2 feet. | |
""" | |
def harvest_time(month, tuber_size): | |
""" | |
>>> harvest_time("May", 1) | |
False | |
>>> harvest_time("May", 2) | |
True | |
>>> harvest_time("May", 3) |
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 should return true if the seafood type is "mollusk" OR | |
it's been frozen for at least 7 days. | |
""" | |
def is_safe_to_eat(seafood_type, days_frozen): | |
""" | |
>>> is_safe_to_eat("tuna", 3) | |
False | |
>>> is_safe_to_eat("salmon", 6) | |
False | |
>>> is_safe_to_eat("salmon", 7) |