Giter Site home page Giter Site logo

python-debug-activity-short-reading's Introduction

Python Debugging and Reading Quiz

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

Deliverables

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 print statement. Otherwise, you won't see any output from running your program!

Requirements:

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.

Code Challenge

Problem 1: We're in a Good Place!

Skill you're practicing: Debugging techniques and variable scope.

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!"

Starter Code

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.")

Expected Output

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!

Actual Output

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 print statements everywhere to print out the values of the variables at various times. For example, inside get_offense(), put a print statement like print('offense is', offense).


Reading Material

Read through the examples in this Data Camp article about data types and type conversion. Then, answer the following questions.

1. Coercion is another term for which of the following concepts in Python?

  • a) Encapsulation
  • b) Inheritance
  • c) Explicit type conversion
  • d) Implicit type conversion
  • e) Floor division

2. Type casting is another term for which of the following concepts in Python?

  • a) Encapsulation
  • b) Inheritance
  • c) Explicit type conversion
  • d) Implicit type conversion
  • e) Floor division

3. What function in Python can we use to check a variable's type?

  • a) type()
  • b) typeof()
  • c) typeof, but it is an operator not a function
  • d) get_type()

4. Which of the following is NOT a primitive data structure?

  • a) Float
  • b) Integer
  • c) List
  • d) String
  • e) Both a and c are not primitives

5. According to the article, what is the main reason to convert a tuple into a list?


See Ya Later!

You're all done. Bye now!

python-debug-activity-short-reading's People

Contributors

brandiw avatar garedb avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.