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
"""" | |
Implement a function that determines if a candidate can be president. | |
According to the US constitution, a presidential candidate must be at least | |
35 years old and have been a US resident for at least 14 years. | |
The age parameter represents a candidate's age and | |
the residency parameter represents their years of residency. | |
""" | |
def can_be_president(age, residency): | |
""" |
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 only return True | |
if both the father allele and the mother allele are "G". | |
""" | |
def has_free_lobe(father_allele, mother_allele): | |
""" | |
>>> has_free_lobe("G", "g") | |
False | |
>>> has_free_lobe("g", "G") | |
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
""" | |
This function should only return True | |
if both the father allele and the mother allele are "C". | |
""" | |
def has_curly_hair(father_allele, mother_allele): | |
""" | |
>>> has_curly_hair("C", "c") | |
False | |
>>> has_curly_hair("c", "C") | |
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
""" | |
How can we communicate the highs and lows of climate change with people who use a different temperature unit? | |
Let's make a temperature converter based on the steps here: | |
https://www.mathsisfun.com/temperature-conversion.html | |
Create a function called celsius_to_fahrenheit that: | |
* takes a single argument, the temperature in celsius | |
* calculates and returns the fahrenheit equivalent | |
Similarly, create another function called fahrenheiht_to_celsius that: |
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
""" | |
Ever wonder how much a "lifetime supply" of your favorite snack is? Wonder no more! | |
Write a function named calculate_supply that: | |
* takes 2 arguments: age, amount per day. | |
* calculates the amount consumed for rest of the life (based on a constant max age of 81). | |
* returns the result | |
""" | |
# This def statement may be incomplete... |
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
""" | |
You know how old a dog is in human years, but what about dog years? Calculate it! | |
Write a function named calculate_dog_age that: | |
* takes 1 argument: a dog's age in human years. | |
* calculates the dog's age based on the conversion rate of 1 human year to 7 dog years. | |
* returns the age in dog years. | |
""" | |
def calculate_dog_age(years): | |
""" |
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
""" | |
Why pay a fortune teller when you can just program your fortune yourself? | |
Write a function named tell_fortune that: | |
* takes 3 arguments: job title, partner's name, geographic location. | |
* returns a fortune of the form: 'You will be a {job_title} in {location} living with {partner}. | |
""" | |
def tell_fortune(job_title, location, partner): | |
""" |
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
from operator import add, sub, mul, truediv, floordiv, mod | |
""" | |
In the console, type expressions that use function calls | |
and correspond to each arithmetic expression. | |
Use the console to check your work. | |
Useful documentation: | |
https://docs.python.org/3/library/operator.html#mapping-operators-to-functions | |
""" |
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
# There are helper functions, | |
# just so that we can avoid calling object methods for demo 1 | |
def read_file(file): | |
return file.read() | |
def count(str, text): | |
return str.count(text) | |
def lower(str): | |
return str.lower() |
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
>>> grammar = """ | |
?start: calc_op | |
?calc_op: OPEN OP operand* CLOSE | |
operand: calc_op | NUMBER | |
OPEN: "(" | |
CLOSE: ")" |