Quizzes & Ans!!
import sys
How do I import the sys module but in a way that you must still use the sys.
namespace?
from pandas import DataFrame
How do I import only pandas.DataFrame so you don't need to type 'pandas.' when
calling DataFrame?
import pandas as pd
How do I import pandas so all I have to type when calling a function is pd?
from sys import *
How do I import everything from the sys module so I do not have to use the sys.
namespace when calling a function?
dir(math)
How do get python to list all of the attributes of the math module?
sys.path
How do I have python tell me what all the places it checks for modules is?
math.ceil(3.6)
How do I round 3.6 up to 4.0?
math.floor(3.6)
How do I round 3.6 down to 3.0?
math.trunc(3.6)
How do I remove the digits after the decimal place in 3.6?
factorial(5)
How do I find the product of all positive number less then or equal to 5?
hypot(3, 7)
I know the length of the two short sides of a triangle. How do I find the length of the long
side? The short sides are (3, 7).
sqrt(16)
How do I find what number times itself is 16?
random.random()
How do I make a random float number from 0 - 1?
randomn.seed(15)
I would like to set 15 as the seed for the random generation of float numbers from 0 - 1.
How do I do that?
choice(store)
store: list[int] = [5, 2, 8, 2] How do I pick a random number from this list?
random.sample(store, 3)
store: list[int] = [5, 2, 8, 2] I would like to pick a three random numbers from this list but I
don't want to reuse indexes that have already been selected. How do I do that? When I
do the a new list will be returned.
platform.platform()
How do I determine the os and version?
platform.machine()
, How do I find out the generic name of the processor which is being used on a
computer?
platform.processor()
How do I find out a detailed name of the processor which is being used on a computer?
platform.system()
How do I find out the generic os name of the computer I am on?
version()
I would like to have a string of my system's release version as a returned to me. How do
I do that?
platform.python_implementation()
How do I find out what python type I am using?
platform.python_version_tuple()
I would like a tuple of the python version returned to me. How do I get the (major, minor,
patch)
__pycache__
How does python speed up the startup time of a script or program? It does not have to
recompile given the source code has not changed.
main.py
If I run cat.py what will the __name__ be?
cat.py
If I run main.py and cat.py is imported into main.py what will the __name__ be for
cat.py?
_dog or __dog
What two ways can I notate dog is a "private" variable?
__init__.py
I need to provide some initialization functions for the files in my package. How can I do
that?
Nested Packages
What do you call it when there are packages inside of subfolders of packages each with
there own __init__ file?
import math, sys
How do you import the math and sys modules in one line?
sys.exit()
How do you raise a SystemExit error? This will exit the program.
AttributeError
What happens if you call a function that does not exits in a module?
from sys import exit as bye_bye
How do I import sys.exit as bye_bye?
round(3.5)
How do I round 3.5 the normal math way?
sys.path.append()
How do I add a place for python to check for modules?
Directory Trees
What style of packaging is it considered when you have a file structure like package?
256
How many code points does the ASCII have?