Skip to content

Instantly share code, notes, and snippets.

View pamelafox's full-sized avatar

Pamela Fox pamelafox

View GitHub Profile
@pamelafox
pamelafox / sum_multiples.py
Created August 30, 2021 06:38
Sum Multiples
""""
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
@pamelafox
pamelafox / count_multiples.py
Created August 30, 2021 06:35
Count Multiples
"""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):
"""
@pamelafox
pamelafox / count_evens.py
Created August 30, 2021 06:31
Count Evens
"""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)
@pamelafox
pamelafox / product_of_numbers.py
Created August 30, 2021 06:28
Product of numbers
"""
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
@pamelafox
pamelafox / grade_assigner.py
Created August 30, 2021 06:19
Grade Assigner
"""
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)
@pamelafox
pamelafox / world_translator.py
Created August 30, 2021 06:15
World Translator
"""
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'
@pamelafox
pamelafox / lesser_num.py
Created August 30, 2021 06:12
Lesser Num
"""
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
@pamelafox
pamelafox / greater_num.py
Created August 30, 2021 06:09
Greater Num
"""
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
@pamelafox
pamelafox / harvest_time.py
Created August 30, 2021 05:50
Harvest Time
"""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)
@pamelafox
pamelafox / safe_to_eat.py
Created August 30, 2021 05:48
Safe To Eat
"""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)