Answers37
What are Python namespaces and why are they important? - ANSWERS-Namespace is where
the variable is operable.
Build-in: contains all build-in functions and exceptions and is in scope through the program.
Global: Contains all the names of variables and functions that are created in the program and
reside outside the functioning is in scope outside functions.
Local: In scope only inside the function. (contains all names within a function)
What are the two ways of documenting Python codes? - ANSWERS-docstrings and comments
What are the five major data science packages in Python? - ANSWERS-Numpy
Scipy
Pandas
Matplotlib
Scikit-Learn
How do you get help to understand a function? - ANSWERS->>> help(say_hello)
help(<function name>)
,How to indicate an even number in an expression? - ANSWERS-even: n % 2 ==0
odd: n % 2 !=0
odd n %2 == 1
What is a boolean? - ANSWERS-true or false value
What is the difference between = and ==? - ANSWERS-One = is to assign the value to a variable
and two == is for comparison.
Why are functions helpful? - ANSWERS-Functions facilitate code reusability, readability, and
maintenance
What is "scope" in terms of programming language python? - ANSWERS-Scope is the term used
to describe the points at which in code variables and functions are defined.
Why is there an error when trying to run this code?
a=int(input())
b=int(input())
if c<a+b:
print("Less than a +b:)
a = b= c=1
print (a,b,c) - ANSWERS-The variable c is not in scope or defined in line 3.
,Which of the following lines of code defines a function named "my_func" that has three
parameters (a, b, and c) where b defaults to 0 and c defaults to "Yes"?
a. my_func(a,b,c):
b. def my_func(a, b(0), c("yes"):
c. def my_func(a, b=0, c="Yes"):
d. def my_func(a, b, c): - ANSWERS-c
Which of the following lines of code will not call a function named "my_func" that has three
parameters (a, b, and c) where b defaults to 0 and c defaults to "Yes"?
a.) my_func( )
b.) my_func(1, c="No")
c.) my_func(1)
d.) my_func(1, 2) - ANSWERS-a
Which of the following will import a specific function "add_numbers" from a library
"adding_library"? - ANSWERS-from adding_library import add_numbers
import <file name without the .py extension> (How to import the full module/libray)
from <file name without the .py extension> import < function name >
There is a function, "my_function". Within that function, a variable called "my_var" is created.
In which namespace does my_var exist? - ANSWERS-local
Python's int( ) function will take an argument and convert it to an integer. In which namespace
does int( ) exist? - ANSWERS-built-in
, Which best describes the difference between a comment and a docstring in Python? -
ANSWERS-Comments do not have a functional purpose but docstrings tie into the Python
documentation help library.
Which of the following is not a Python library used frequently for data science applications?
a.) NumPy
b.)SciPy
c.) Pandas
d.) DataPyScience - ANSWERS-d.
What is the difference between a syntax error and an exception? - ANSWERS-Exceptions are
run-time errors that cause application termination, if remaining untreated. Syntax errors are
errors that prevent an application from running because code does notconform to the language
rules.
Which of the following options describes the best way to deal with a syntax error? - ANSWERS-
Find the section of code referenced by the interpreter's error message as well as understanding
the code related to this section, to identify the problem.
If I try to open a file that does not exist using Python's open function, what will likely be the
result? - ANSWERS-A FileNotFoundError exception
Some code is being written where an exception may occur. The exception should be handled
properly so the application will not crash. The specific exception that may occur is the
ZeroDivisionError exception. Regardless of whether or not the exception occurs, there's some
cleanup code that needs to run. What should be done? - ANSWERS-Implement a try block, a
specific ZeroDivisionError except block, and a finally block.