WorksheetsPython L3 Concepts
Total questions: 40
Worksheet time: 20mins
What is Tkinter?
A python based programming language used for creating GUI applications
A toolkit that translates python into HTML for creating visual web interfaces
A text editor built into the operating system that we can modify
A binding that allows us to use Tk, a toolkit written in C, to create GUI applications with python
The ____ of a tk button is the function that runs when the button is clicked.
object
command
control
text
A ____ is a graphical component of a tkinter GUI with a specific purpose.
gadget
box
frame
widget
Why would we typically use a lambda function?
To define a named class method
To create a function that takes in no arguments
To create a function from changing values and save it to use later
To replace a conditional statement in our code
The command of a button in tkinter is
The text displayed on the button
The function that runs when the button is pressed
Always a lambda function
Always a defined class method
How do you access the text field of a tkinter button?
text = mybutton["text"]
text = mybutton.getLabel()
text = mybutton.getText()
text = mybutton.text.get()
Which tkinter class does our Application inherit from?
tk.Object
tk.Frame
tk.Text
tk.Label
How do we place a button in an Application using a grid layout?
button.place(r=row, c=column)
button.set(row=r, column=c)
button.show(row=r, column=c)
button.grid(row=r, column=c)
What function is used to remove a widget from an application?
.remove()
.delete()
.active()
.destroy()
How would we create a function that returns five times the input value?
y = lambda x, x = x * 5
y = x * 5
lambda = x * 5
y = lambda x: x * 5
The ____ is the encrypted text of a message.
plaintext
ciphertext
deciphertext
cryptext
A shift cipher disguises a message by :
Replacing each letter by another letter in a randomly generated sequence of letters
Replacing each letter by a number in a code book that was agreed upon earlier
Replacing each letter by another letter in the alphabet shifted by a set amount called a key
Replacing each word by another sequence of letters according to a set of rules
The modulo operator:
performs repeated addition
performs division and returns the remainder
performs division and returns the quotient
gives the percent value of a number
When we load information about an object from a .json file:
It is a Python object, we can use it right away
It is a Python dictionary, and we need to set the object's variables equal to the values of the dictionary
It is a Python string, and we need to parse information about the object's variables from the string before we can use it
We can't save data about objects in Python to a .json file
Why do we use modulo to implement a shift cipher?
Because adding the key to a letter's value can result in a number greater than 25, and we need to wrap the result back to 0
Because the modulo function performs the conversion between the letter and its ASCII numerical representation
We don't need to use modulo
Because modulo turns the decimal result of division into a fraction that we can use
What is recursion?
It is another name for a loop
It is a data structure, like a dictionary, that we can use to store information
It is a principle of object oriented computer programming that allows us to borrow methods and attributes from other classes
It is a method of repeatedly applying the same steps to smaller and smaller parts of a larger problem
How do we implement recursion?
By creating a new variable of type recursion
By using many nested for-loops
By making copies of our program to run in different locations
By calling a function from within itself
Why is it important to consider the termination condition when using recursion?
The termination condition is a error that we can run into when we implement recursion
The termination condition tells the program when it should stop running, without it the program would recurse forever
The termination condition is an optional part of recursion that can change the outcome of the program
The termination condition prevents us from implementing recursion, so we have to remove it from our program
What is a test user and why do we need to add them in the OAuth consent screen page?
Test users are random users that will be assigned to test our app in order for it to be verified
Test users need to be added because they are the only Google accounts that will be allowed to log in to our app
Test users are users that will be notified when we release new versions of our app
Test users are accounts that don't have to authorize our app in order to use it, this allows them to skip the consent screen when they log in
How does a user log into Google from our app?
We save the user's gmail address and password to a file and use that to log in
The code opens a browser window and the user completes an authorization flow
The user is asked to type their gmail address and password into the shell when the code is run
The user doesn't have to log in as long as their gmail address was added to our list of test users
Google APIs:
Allow you to use google services and access account data with read only permissions
Allow you to use google services and access account data with full permissions
Allow you to use google services and access data with the permissions requested by the app scopes and authorized by the user
Allow you to use google services but do not allow you to access user account data
What is the librosa library used for?
Analyzing audio
Manipulating audio
Applying effects to audio
Librosa is used for all of these
What does the map() function do?
It creates a 2D visualization of an object
It applies a function to each element in a list or other iterable type
It iterates through a list until it finds the specified item and applies the function to it
It applies a function once collectively to an entire list
When will a pygame sound stop playing?
When the end of the sound file is reached
When the .stop() function is called
When the next sound is played
When the end of the sound file is reached or the .stop() function is called
The map function allows us to:
avoid defining a list
avoid writing a for-loop
define an unnamed function a single line
convert an object to a list of attributes
What are sockets?
Endpoints for sending and receiving data used in internet communication
The numbers which identify your computer to other computers on a network
A number assigned to you by your internet service provider
A place to plug in your laptop charger
What is TCP?
Telecommunications Connection Process
Transfer Cable Port
Transmission Control Protocol
Traffic Consistency Paradox
What happens in TCP that makes it more reliable than simply sending information to a destination?
The sender always sends multiple copies of information at a time to its destination in case one copy is lost
The receiver sends an acknowledgement message to the sender to let them know the information was received
The sender always sends information to the main destination as well as a backup destination in case the receiver is busy
The receiver has to initiate communication, otherwise all incoming messages are blocked
To create a client and server connection on one computer, you must:
Run the client program only, the server is running on the internet
Run the server program in first an online Python environment and run the client in an IDE like Thonny
Run the client program first in the terminal on your computer, then run the server program in an IDE like Thonny
Run the server program first in the terminal on your computer, then run the client program in an IDE like Thonny
What are all the possible parts of a try block in Python?
try, catch
try, catch, finally
try, except
try, except, finally
What does connecting over localhost do?
Allows us to communicate over the Internet
Creates a connection within the same machine
Creates a connection between the computer and our wifi network which acts as the host
Allows us to connect over our local area network
What does the echo client do?
Waits for a connection, receives a message, and sends the message back to the server
Establishes a connection with the server, sends a message, and then confirms that is has received the message back
Waits for a connection, then sends a welcome message to the server
Establishes a connection and receives a welcome message from the server
A message sent over a connection is:
A string containing the message text
A python object called a SocketMessage
An encrypted string containing the message text that must be decoded
A byte array containing the message text that must be decoded
What are threads?
Identical copies of a program file running in different locations
Methods that are inherited from a superclass
Tasks running simultaneously from the same code
Connections between each client and server
Starting a new thread:
Runs the entire python file from the top
Runs a specified method, but cannot take any arguments
Runs a specified method with the arguments provided
Runs only the part of the code within the thread loop
In a client-server connection where a single server can connect to one or more clients at the same time, which part of the code requires us to implement multithreading?
The server code
The client code
Both require multithreading
Neither require multithreading
Which is NOT a necessary step in order to use Google APIs?
Register our app and configure the OAuth consent screen
Create a credentials file and download it
Enable the API we want to use in the Google API library
Defining all scopes in the developer console
What does the echo server do?
Waits for a connection, receives a message, and sends the message back to the client
Establishes a connection with the client, sends a message, and then confirms that is has received the message back
Waits for a connection, then sends a welcome message to the client
Establishes a connection and receives a welcome message from the client
To use sounds in pygame, we must include:
pygame.mixer.init()
pygame.init()
either pygame.mixer.init() or pygame.init()
There is no requirement to use pygame sounds other than importing pygame
How do thread locks work?
Locks prevent any threads from accessing the parent thread variables until a certain point in the program
Locks block specific threads from ever editing the shared variables, so one thread becomes the "writer"
Locks put access to variables on a timer, so a given thread may have access for only a set amount of time before access is passed to the next thread
Locks allow a thread to gain access to a variable and block other threads from accessing it until the variable is unlocked
