Computer Science 113: Programming in Python study.com
What is the concatenation operator?
+
What escape sequence is used for a tab?
/t
How many different values can a Boolean contain?
2
To draw a Rectangle object using GraphWin the constructor requires _____ parameter(s).
A Rectangle object also takes two Point objects as values: g = Rectangle(Point(80, 100), Point(150, 150))
What is a dictionary in python?
A built-in data structure that stores key-value pairs with each key being unique.
What is a delimiter?
A character that separates the data field values
How does using a debugger in an integrated development environment benefit an individual who is writing code?
A debugger walks through code in a systemic and automatic manner to find bugs, making the process less time consuming.
A list data type is also referred to as:
A one-dimensional array
A computer program can be best described as _____. Choose the best answer
A set of instructions or programs designed to complete a particular task
What is an algorithm?
A well-defined procedure that makes it possible for computers to solve problems.
To draw an Oval object using GraphWin the constructor requires _____ parameter(s).
An Oval object is formed by two points. For example: g = Oval(Point(80, 100), Point(150, 150))
Why is Python a scripting language?
Because it is processed at runtime by the interpreter
what would be an appropriate reason for using a tuple in Python?
Better performance
Which of the following CANNOT be stored inside a dictionary?
Binary tree
Which of the following is not a numeric data type?
Boolean
What are the two main parts of a programmer's job?
Breaking a problem into a series of steps and describing those steps to the computer so it can solve the problem
What widget can we use that when clicked can cause some action to take place?
Button
How can a dictionary be created?
By using {} curly braces
What is a CSV File?
CSV files are universal text files that contain tabular data, also known as comma-separated values. In CSV files, data is defined by rows and columns, where a new line depicts a new row of data,
tuple(seq)
Change a list to a tuple
CSV files use delimiters to separate which data?
Column data
What does the acronym CSV stand for in its full form?
Comma Separated Value
cmp(tuple1, tuple2)
Compare two tuples
What does the count() method do?
Counts the total number of a specified object in a list.
This method is used to remove the last item from the queue
Dequeue
This operation adds an object to the queue.
Enqueue
What widget can we use to allow a user to enter a value?
Entry
A data type where values can only represent one of a limited number of pre-defined categories is called a(n) _______ data type.
Enumerated
four main concepts of Object oriented programming
Four core concepts of object-oriented programming are abstraction, encapsulation, inheritance and polymorphism.
How do functions differ from methods?
Functions are independent of classes, and methods are defined within a class.
The max size for the number of objects in a python queue is _____
Indefinite
What does the append() method do?
It can add an object or a list to the end of a list.
What is the most accurate statement about the below code: canvas.bind("<Button-1>", self.draw)
It connects the clicking of left mouse button to method draw
What widget can we use to display text data?
Label
What is the proper way to insert '5' into the 5th position of the MyList that contains '0','1','2','3','4','6','7','8','9','10'
MyList.insert(5, '5')
Event ''<Any KeyPress>'' when used in Tk.bind method, is used for _____
Pressing any key on the keyboard anywhere on the Tk graphics window
What would happen if our program did not call mainloop() method for Tk instance?
Program would end
Which of the statements will create a Rectangle object with center point as x=50 and y=50?
Rectangle(Point(0, 0), Point(100, 100))
max(tuple)
Returns item with the highest value
min(tuple)
Returns item with the lowest value
Mary plotted two histograms in the same figure. The first one contains US population age, and the second one contains UK population age. How can she properly identify which graph belongs to which data?
She could put a legend using: plt.legend('US population', 'UK population').
len(tuple)
Shows the length of the tuple
Gwen is an IT programmer for a small, non profit company. She's been assigned to write some new code for her company's payroll department to assist with the roll-out of a new pay for performance system. The new code will affect employees' pay grades, salaries, and bonuses. Gwen has written pseudo-code and the actual code. What should be her next step in the process?
Test and debug the code
There are two types of files in python:
Text files: Files which store character data. Binary files: Files which store binary data such as images, audio, video and zip files.
How Does a Python Queue Work?
The Rear of the queue is where objects or items are input into the sequence, also called to enqueue. The Front of the queue is where the objects or items are removed from the sequence, also called dequeue.
What are the two most important skills a programmer must have?
The ability to analyze and understand a problem and describe it to a computer
What does the first row in the CSV file typically contain?
The column names of the data
John wrote the following code: prices = [2.34,9.87,12.34,98.00] import matplotlib.pyplot as plt plt.plot(prices,'v+') After running, he does not see the figure which is supposed to be created with the code above. What is the problem? plt.plot
The command plt.show() should be added at the end of the script.
Which of the following functions is used to open a file in Python?
The open() function
For which of the following modes would you get a FileNotFound error if the specified file does not exist?
The read mode, 'r'
in this line of code what does the 5 mean? q1 = queue.Queue(5)
The size of the queue will be 5 and no more objects can be added to it.
How does the IDE component, known as syntax highlighting, aid developers with writing program code?
The tool makes it easier to recognize the various elements of code.
Why would the following code fail on the tuple? my_tuple = ('L', 'M', 'N', 'O', 15) print(min(my_tuple))
The values are not all numeric
what does this print? print('This is line 1\n\nThis is line 3')
This is line 1 This is line 3
To draw a Circle object using GraphWin the constructor requires _____ parameter(s).
To create a Circle object, we need to specify the point of its center and the radius. g = Circle(Point(125, 125), 50)
What will result in an error when using the list sort() method?
Trying to sort a list that contains character strings and numbers.
To draw a Text object using GraphWin the constructor requires _____ parameter(s).
We can also create a Text object giving it the anchor Point where the text starts and the text value: g = Text(Point(125,125), "Hello")
What is the importance of syntax in programming?
When code contains syntax errors, the program will not execute correctly.
Canvas widget in Tkinter is a _____
Widget which provides a rectangular area where we can draw widgets
Canvas, create_text method needs the following parameters:
X and Y coordinates where to start drawing and the text to draw
what is the escape sequence for a single quotation mark
\'
what is the escape sequence for a double quotation mark
\''
What is the escape sequence for a new line?
\n
what is a tuple
a tuple is an important data structure for use in Python. A tuple is like an array in other programming languages: Once you create and assign values to the tuple, it is unchangeable.
Which is not a primitive data type?
array
Sally is writing some Object-Oriented Program code for a vehicle which contains the attributes (manufacturer, color, and price), along with what she wants the vehicle to be able to do (start, drive, and park). This is known as a _____.
class
What is the default delimiter of a CSV file
comma
To draw a rectangle using Canvas widget's method we can call:
create_rectangle(x1, y1, x2, y2)
Which of the following concepts is closely related to Search algorithms?
dictionary
what is dict(), insert(), pop(), append(), known as? hint:(very generalized term for them)
functions
To add an arrow to the right side of the Line object using GraphWin, the setArrow method parameter is a String value _____
g.setArrow("last") last
Which method is used to remove an item from the queue?
get()
Which method can you use to access data in a dictionary?
get() method
Which of the following statements are valid ways of plotting the following vector: y = [-4,-2,2,6,10]?
import matplotlib.pyplot as plt plt.plot(y)
What is the code used to generate a visualization of the function: f(x) = 3x+1 in the domain x = [0,3]?
import numpy as np x = np.linspace(0,3,100) y = 3*x+1 import matplotlib.pyplot as plt plt.plot(x,y)
Which function is used to obtain keyboard input?
input()
Which Python list methods are similar?
insert() and append()
A code editor that is used to check syntax, format, run, and test code is known as a/an _____.
integrated development environment
The programmer's toolbox contains
math, logic, the five basic kinds of programming instructions, and how to put all those together in something called an algorithm.
A _____ is a procedure associated with a class that describes an action an object is able to perform.
method
A binary search algorithm begins at the _____ of a list.
middle
my_cards is a tuple, what does the code output print(my_cards * 4)
my_cards objects 4 times
what is a correct implementation of a tuple in Python?
new_tuple = ("Paul", "John", 63)
Sally is continuing work on her Object-Oriented Program and is writing code for a car, truck, and bus. These items under the class called vehicle are referred to as _____.
objects
what would be the most appropriate use case for a Python tuple?
piano keys
what kind of graph does this output? import matplotlib.pyplot as plt x = 10,20,50,20 plt.pie(x) plt.show()
pie chart
What is the command required to produce a plot with vectors t and z using blue plus sign?
plt.plot(t,z,'+b')
to title a graph what would you code
plt.title('Regression f(x)')
Mary used the following code to plot some data using Matplotlib: import matplotlib.pyplot as plt x = [10,20,30] y = [100,200,300] plt.plot(x,y,'ro') Now she wants to compare this with another plot that she had done before using the following commands: x = [10,45,90] y = [50,150,200] plt.plot(x,y,'ro') How should she reset the limits of x and y axes so she can see the whole data for both datasets?
plt.xlim(10,90) plt.ylim(50,300)
Which function is used to provide output to the screen?
print()
here you have a list emps = [100, 200, 300, 400, 500, 600, 610] how can you convert it into a tuple?
process_emps = tuple(emps)
You want to read only the first twenty characters of a file. Which of the following functions would you use?
read(n)
Which of the following represents the simplest algorithm to search an unsorted list of items in order to determine whether a particular item occurs in the list or not?
sequential or linear search, It is not very efficient relative to other algorithms such as binary search, but it also does not require that the items are sorted, as is the case with binary search.
what is the output? strString= 'study.com is great' print(strString.replace('great','WONDERFUL'))
study.com is WONDERFUL
CSV files contain which type of data?
tabular data
in this code what does the 'ok' mean? ax = plt.plot(x,y,'ok')
the graph that will be output will have o's as the points and k will make the o's black
True of false lists use brackets and dictionary's use curly braces
true
A memory location that can store a value within a program is called a/an:
variable
Which of the following is the correct syntax for 'with' statement?
with open(filename, mode) as fileObject: body