In this homework, you're going to write code for a challenge problem and answer some reading comprehension questions.
You will practice these programming concepts we've covered in class:
- Type conversion
- Escape characters and string formatting
- Debugging techniques
- Variable scope
Part of this homework will be code challenges and part will be reading with comprehension questions.
For the reading quiz, make a text file called answers.txt
and use it to compile your answers to the numbered questions.
For each of the code challenges listed below, you will create a new .py
file and write code to solve the problem. For example, you would create problem1.py
with your solution code to the first problem. Run the file from the command line to check your work.
Reminder: On your laptop, you can run the file from your command line with the following:
python problem1.py
Hint: Make sure you are printing something out with the
By the end of this, you should have:
- One
.py
file for the code challenge. - One text file with answers to the five reading comprehension questions.
Jason is a huge Jacksonville Jaguars fan. The team isn't doing great now, but he has faith: "All we need is a defense, and an offense, and some rule changes!"
offense = False
defense = False
rule_changes = False
def get_offense():
offense = True
def get_defense():
defense = True
def get_rule_changes():
rule_changes = True
if offense and defense:
get_rule_changes()
get_offense()
get_defense()
print("How are the Jags doing?\n")
print("We have offense:", offense)
print("We have defense:", defense)
print("We have some rule changes:", rule_changes)
if offense and defense and rule_changes:
print("We're going to the Super Bowl!")
else:
print("I can't predict the future, but no, the Jaguars will never win the Super Bowl.")
How are the Jags doing?
We have offense: True
We have defense: True
We have some rule changes: True
We're going to the Super Bowl!
How are the Jags doing?
We have offense: False
We have defense: False
We have some rule changes: False
I can't predict the future, but no, the Jaguars will never win the Super Bowl.
Hint: Include a bunch of
get_offense()
, put aprint('offense is', offense)
.
Read through the examples in this Data Camp article about data types and type conversion. Then, answer the following questions.
- a) Encapsulation
- b) Inheritance
- c) Explicit type conversion
- d) Implicit type conversion
- e) Floor division
- a) Encapsulation
- b) Inheritance
- c) Explicit type conversion
- d) Implicit type conversion
- e) Floor division
- a)
type()
- b)
typeof()
- c)
typeof
, but it is an operator not a function - d)
get_type()
- a) Float
- b) Integer
- c) List
- d) String
- e) Both a and c are not primitives
You're all done. Bye now!