Python Basics: External Libraries

Quiz
•
Computers
•
University - Professional Development
•
Medium
Jeff Thuong
Used 1+ times
FREE Resource
6 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
How does the following do?
from some_library import some_code
Import the library some_library and rename it "some_code"
(i.e. it is an alias)
Import "some_code" from some_library
(it could be a function for example)
Raise an Exception
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
How does the following do?
import some_library as some_code
Import the library some_library and rename it "some_code"
(i.e. it is an alias)
Import "some_code" from some_library
(it could be a function for example)
Raise an Exception
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
How does the following do?
from some_library import *
Import the library some_library and rename it "*"
(i.e. it is an alias)
Import everything from some_library and make it available directly
(e.g. using "pi" instead of "math.pi")
Raise an Exception
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What does the function say_hi do?
Print Hello on the screen and return None
Return a Path("Hello") (whatever that is)
Print Hello on the screen and return a Path("Hello")
Raise an Exception
Answer explanation
This is a typical example of why it is dangerous to use Python keywords (print, list, dict, str...) as variable name or "alias" during import.
Here, we are replacing "print" with something else and you will have very weird behavior.
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
The libraries math and numpy both have a function "log": what will happen in the code of screenshot?
An error because "log" is not found
Print the value of log of 1000 base 10 from math library ... which is 3
Trying to call log from numpy library and raise an Exception
Raise an Error because we try to import log from both math and numpy
Answer explanation
☢️This is an example about why it is dangerous to do:
from a_module import *
It can over-write any function that is previously defined and lead to some weird behavior.
And that is why a lot of people recommend to never use "import *".
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What happens after following line:
from math import pi, log
You can use both math.pi and math.log
e.g. print(math.pi, math.log(100, 10))
You can use both pi and log directly
e.g. print(pi, log(100, 10))
Raise an Exception
Answer explanation
💡You can import several things inside a library by separating by a comma.
Similar Resources on Wayground
10 questions
Python_middle

Quiz
•
Professional Development
10 questions
Estructuras de memoria

Quiz
•
Professional Development
10 questions
AFP Midtvejsevaluering

Quiz
•
University
10 questions
TECHNOLOGY FOR TEACHING AND LEARNING

Quiz
•
University
8 questions
Programování - opakování

Quiz
•
University
10 questions
PAA - Análise Assintótica

Quiz
•
University
10 questions
Quiz Pit-Stop 3 (Security and the Internet)

Quiz
•
University
8 questions
Рандом и списки

Quiz
•
Professional Development
Popular Resources on Wayground
10 questions
Video Games

Quiz
•
6th - 12th Grade
20 questions
Brand Labels

Quiz
•
5th - 12th Grade
15 questions
Core 4 of Customer Service - Student Edition

Quiz
•
6th - 8th Grade
15 questions
What is Bullying?- Bullying Lesson Series 6-12

Lesson
•
11th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
22 questions
Adding Integers

Quiz
•
6th Grade
10 questions
Exploring Digital Citizenship Essentials

Interactive video
•
6th - 10th Grade
Discover more resources for Computers
10 questions
How to Email your Teacher

Quiz
•
Professional Development
20 questions
Definite and Indefinite Articles in Spanish (Avancemos)

Quiz
•
8th Grade - University
7 questions
Force and Motion

Interactive video
•
4th Grade - University
36 questions
Unit 5 Key Terms

Quiz
•
11th Grade - University
7 questions
Figurative Language: Idioms, Similes, and Metaphors

Interactive video
•
4th Grade - University
15 questions
Properties of Equality

Quiz
•
8th Grade - University
38 questions
WH - Unit 3 Exam Review*

Quiz
•
10th Grade - University
21 questions
Advise vs. Advice

Quiz
•
6th Grade - University