SAT 4310 Final Exam Practice
( Indicates where string extraction is to start, ) Indicates where string extraction is to end. The capturing order is: from external to internal. In order to extract both email addresses and user names, as follows: # return [('[email protected]', 'whzhou'), ('[email protected]', 'tom2020'), ('[email protected]', 'kati'), ('[email protected]', 'hadoop')] Fill in the blank in the following codes. s= "My e-mail is [email protected]. His E-mail is [email protected]. Her E-mail is [email protected]. His father's Email is [email protected] " email=re.findall("______" ,s) ((\w+)@\w+\.\w+) ((\w)@\w\.\w) (\w+@(\w+)\.\w+) ((\w+)@\w+.\w+)
((\w+)@\w+\.\w+)
In Python, t = (23, 'abc', 4.56, (2,3), 'def'). The output of t[2:] is ('abc',4.56, (2,3), 'def') (4.56, (2,3)) None of them (4.56, (2,3), 'def')
(4.56, (2,3), 'def')
Read the following code snippet which is designed to count the frequency of the names in the name list: Name_list = ['csev', 'cwen', 'csev', 'zqian', 'cwen'] counts = dict() for name in Name_list : counts[name] = counts.get(name, ____) + 1 print counts Select the best answer to complete the blank in the code snippet. '' -1 1 0
0
The purpose of the following codes is to multiply num1 and num2 and then show the results. Select the correct answers to fill in the blanks. ---------------------------------- num1=3 num2= 7 s= "{_______} +{________}={________}".format(num1+num2, num1,num2) print(s) --------------------------------- 1,0,2 1,2,0 0,2,1 0,1,2
1,2,0
According to Python name conventions, which of the followings cannot be a variable's name in Python? _____. abc_123 _abc_123 this_is_a_variable 123_abc
123_abc
The gray level of binary images is _______ 2 1 256 0
2
What is the output of the following code block? class sample: x = 23 def increment(self): self.__class__.x = self.__class__.x + 1 a = sample() b = sample()b.increment() print(a.__class__.x) 25 23 24 0
24
A negative image is known as a color-reversed image. Fill in the blanks in the following Python function and convert a 24-bit color image to its negative image. def negativePixel(oldPixel): newRed=______-oldPixel.getRed() newGreen=______-oldPixel.getGreen() newBlue=______-oldPixel.getBlue() newPixel=image.Pixel(newRed,newGreen,newBlue) return newPixel 65535 maximum value of the image pixels 1 255
255
What is the output of the following Python statement? >>> len("X\nY") 2 4 3 5
3
In Python, t = (23, 'abc', 4.56, (2,3), 'def'). The output of t[-3] is 4.56 'def' 23 (2,3)
4.56
In the regex \1 matches the repeated word in parentheses. What is the output of the following codes? s= "88coUY88co is good!" x = re.search(r'(\d{2}\w{2}).*\1', s) print(x) 88coUY88co 88co 88co88co ''
88coUY88co
Compare the following two strings in Python: 'aa' _______ 'aaz' > = <
<
In image contrast stretching, the current range of intensity values ______________ the desired range of values Unknown > < =
<
For the image tag in a HTML page, fill in the blank to extract image sources and names with a regular expression. str=""" <img src="Michigan%20Tech%20Pictures_files/IMG_5867g3.jpg" alt="1" width="700" height="231">""" pattern="______" img_list=re.findall(pattern,str) <img\w+src=\"([\S\.-/]+/(\S+jpg))\"\w <img\s+src=\"([\S\.-/]+/(\S+jpg))\"\s <img\s+src=\"(\S\.-/+/(\S+jpg))\"\s <img\s+src=\"[\S\.-/]+/\S+jpg\"\s
<img\s+src=\"([\S\.-/]+/(\S+jpg))\"\s
Which of the following is not a Python Comparison Operator? _____. = <= != == <
=
Compare the following two strings in Python: 'a' _______ '0' = < >
>
Compare the following two strings in Python: 'a' _______ 'A' < > =
>
Which of the following is (are) a Python Logical Operator? _____. or All of the above and not
All of the above
About Tkinter in Python, which of the following statements is correct? Tkinter is the inbuilt python module that is used to create GUI applications. It is one of the most commonly used modules for creating GUI applications in Python as it is simple and easy to work with Tkinter is the inbuilt python module that is used to create GUI applications. It is one of the most commonly used modules for creating GUI applications in Python as it is simple and easy to work with The Tkinter module allows the creation of simple GUI programs All of them
All of them
About cryptography, which of the following statements is correct? The art of breaking ciphers is called cryptanalysis Cryptography is the use of mathematical operations to protect messages traveling between parties or stored on a computer The art of devising ciphers is called cryptography A cipher is an algorithm for performing encryption or decryption All of them
All of them
About techniques for Images, which of the following statements is correct? Frequency domain watermarking first converts the image to the frequency domain and then applies the watermark in the low frequency regions. Spatial watermarking just changes some of the values of the pixels in the lower bit plane; e.g., changes some of the bits from 1 to 0 or 0 to 1. All of them
All of them
Main techniques for image security include: Hybrid methods Image steganography (hiding images) Add watermark to images All of them Encrypt images
All of them
Quality of digital images include: spatial resolution (proximity of image samples in image plane) spectral resolution (bandwidth of light frequencies captured by sensor) All of them time resolution (interval between time samples at which images captured) radiometric resolution (number of distinguishable gray levels)
All of them
Regarding user interface, which of the following statements is correct? GUIs popularized the use of the mouse GUIs allow the user to point at graphical elements and click the mouse button to activate them A graphical user interface (GUI) allows the user to interact with the operating system and other programs through graphical elements (icons, buttons, slider bars, etc.) on the screen All of them Command line interface displays a prompt and the user types a command which is then executed
All of them
Which of the following methods can be used to convert a color image to a grayscale image? use luminance value: L= 0.2998r+0.587*g+0.114*b use the average of r,g,b : (r+g+b)/3 All of them make both green and blue value to be red value in the same pixel
All of them
Which of the following statements are correct about tuples and lists? Tuples are immutable and have fewer features. All of them Lists slower but more powerful than tuples. Lists can be modified and they have many handy operations and methods We can convert tuples and lists using list() and tuple()
All of them
Which of the following statements is correct? MySQL is compatible with standard SQL All of them MySQL is frequently used by Python MySQL is an SQL (Structured Query Language) based relational database management system (DBMS)
All of them
What can Python do? _____ is correct. Python can be used on a server to create web applications. It can also be used alongside software to create workflows Python can be used to handle big data, artificial intelligence (machine learning), and perform complex mathematics. Python can be used for rapid prototyping, or for production-ready software development. Python can connect to database systems. It can also read and modify files All statements are correct.
All statements are correct.
Which of the following Tkinter widget(s) can be used to gather the text input from users? Both Entry and Text Entry Text Label
Both Entry and Text
Digital watermarks can be only visible. Is this statement true or false? True False
False
Is the following statement true or false? In public-key encryption/decryption, the private key is used to encrypt messages. True False
False
Is the following statement true or false? When hiding an image in an image during image steganography, the image you want to hide can be bigger than the cover image. True False
False
Regarding "break" and "continue" in Python, which of the following statements is wrong? _____. If the break statement is inside a nested loop (loop inside another loop), the break statement will terminate the outermost loop. The break statement terminates the loop containing it. Control of the program flows to the statement immediately after the body of the loop. The continue statement is used to skip the rest of the code inside a loop for the current iteration only. Loop does not terminate but continues on with the next iteration. In Python, break and continue statements can alter the flow of a normal loop.
If the break statement is inside a nested loop (loop inside another loop), the break statement will terminate the outermost loop.
In order to include the python files already existed, which keywork should be used? _____. Have Import Include Search
Import
The output of the following codes is _______________. total = 0; # This is global variable. def sum( arg1, arg2 ): total = arg1 + arg2; # This is local variable print("Inside the function local total : ", total) return total; # Now you can call sum function sum( 10, 20 ); print("Outside the function global total : ", total) Inside the function local total : 30 Outside the function global total : 30 Inside the function local total : 0 Outside the function global total : 0 Inside the function local total : 30 Outside the function global total : 0 Inside the function local total : 0 Outside the function global total : 30
Inside the function local total : 30 Outside the function global total : 0
Which of the following statements is wrong? List is a mutable ordered sequence of items Items in a tuple should have the same data type. String is an immutable ordered sequence of chars Tuple is an immutable ordered sequence of items
Items in a tuple should have the same data type.
For the methods of Sets, which statement is wrong? None of them You can use the pop method to remove and return an arbitrary value from a set You can update a set by adding elements from one set to another set. You can use the update() method to do this You can use the method add to add a value to a set You can use the clear method to remove all values from a set An existing set can be copied to a new set by using the copy() method The remove() method raises an error when the specified element doesn't exist in the given set, , however the discard() method doesn't raise any error if the specified element is not present in the set and the set remains unchanged
None of them
Regarding classes, objects, and instances in Python, which of the following is wrong? The core tasks for object oriented programming are to build different classes and thus construct different objects based on the classes to achieve aims. A class is a special data type which defines how to build a certain kind of object. The class also stores some data items that are shared by all the instances of this class. Everything in Python is really an object None of them Instances are objects that are created which follow the definition given inside of the class. Objects belong to classes. Classes reflect concepts, objects reflect instances that embody those concepts.
None of them
Regarding database driver, which of the following statements is wrong? MySQL provides standards-based drivers for JDBC, ODBC, and .Net enabling developers to build database applications in their language of choice. None of them A database driver is a software helps program to access database Each database implementation requires its own driver and each driver could have different syntax for its use in a program. MySQL Python connector is a driver for python programming to access MySQL databases.
None of them
Regarding functions and the benefits of modularization a program with functions, which statement is wrong? We can test and debug each function individually. Functions can speed up the software development. A function has a group of statements within a program that perform as specific task Functions promote code reuse, so we can write the funciton codes once and call it multiple times. None of them Different team members can write different functions, so functions can facilitate the team development.
None of them
Regarding methods in classes, which of the following statements is wrong? We define a method in a class by including function definitions within the scope of the class block There must be a special first argument self in all of method definitions which gets bound to the calling instance There's no "destructor" method for classes in Python None of them
None of them
Regarding the method "__init__()" in Python classes, which of the following statements is wrong? __init__ serves as a constructor for the class. Usually does some initialization work The arguments passed to the class name are given to its __init__() method An __init__ method can take any number of arguments. Like other functions or methods, the arguments can be defined with default values, making them optional to the caller. None of them
None of them
Which of the following statements about "self" and data attributes in Python classes is wrong? None of them Although you must specify self explicitly when defining the method, you don't include it when calling the method. The first argument of every method is a reference to the current instance of the class In __init__, self refers to the object currently being created; so, in other class methods, it refers to the instance whose method was called
None of them
Which of the following statements is wrong? NumPy (Numerical Python) is the fundamental package for scientific computing with Python Matplotlib is a popular plotting library in python. TensorFlow is a Python library for fast numerical computing created and released by Google. It is a foundation library that can be used to create artificial intelligence/ deep learning models. None of them SciPy (Scientific Python) is a scientific computation library that uses NumPy underneath
None of them
Regarding the "try/except group", which of the following statements is wrong? Only a single except suite can be associated with a try suite if there is an error but no exception handling is found, give the error to Python if no exception in the try suite, skip all the try/except to the next line of code if an error occurs in a try suite, look for the right exception; if found, run that except suite and then skip past the try/except group to the next line of code
Only a single except suite can be associated with a try suite
____________ are the basic building blocks of all digital images. They are small adjoining squares in a matrix across the height and width of your digital image. Pixels Matrix Image Header
Pixels
The output of the following codes is _______________. x = "awesome"def myfunc(): global xx = "fantastic"myfunc()print("Python is " + x) Python is None of them Python is fantastic Python is awesome
Python is fantastic
About the features of Python, which statement is wrong? _____. Python can be treated in a procedural way, an object-oriented way or a functional way. Python works on only Microsoft Windows Operating Systems. The most recent major version of Python is Python 3 Python runs on an interpreter system, meaning that code can be executed as soon as it is written. This means that prototyping can be very quick. Python has syntax that allows developers to write programs with fewer lines than some other programming languages.
Python works on only Microsoft Windows Operating Systems.
Regarding defining and calling a function, which statement is wrong? Any input parameters in a function should be placed within the parentheses. The first character of a function name can be a number. When a function is called, interpreter jumps to the function and executes statements in the block, and then jumps back to part of program that called the function A main function is called when the program starts
The first character of a function name can be a number.
Regarding graphical user interfaces, which of the following statements is wrong? The priority determines the order in which things happen GUI programs respond to the actions of the user, thus they are event driven User interface requires the support of harward devices.
The priority determines the order in which things happen
Regarding local variables, which of the following statements is correct? None of them Different functions cannot have local variables with the same name Local variable can be accessed by statements inside its function which precede its creation The scope of a local variable is the function in which the local variable is created
The scope of a local variable is the function in which the local variable is created
Regarding sets in Python, which statement is false? A set is an unordered collection of items Every element in a set is unique, iterable and immutable A set can only contain unique elements The set as a whole is immutable
The set as a whole is immutable
Compared to low-level digital image processing, high-level digital image processing, including object description and classification, is more intelligent and requires more complex computer algorithms. Is this statement correct? True False
True
In order to use MySQL Python connector, you should import this package/ module at the beginning of your program: mysql.connector. Is this statement true? True False
True
Is the following statement true or false? A file directory must contain a file named __init__.py in order for Python to consider it as a package True False
True
Is the following statement true or false? If a requested method is not found in the derived class, it is searched for in the base class. This rule is applied recursively if the base class itself is derived from some other class. To execute the method in the parent class in addition to new code for some method, explicitly call the parent's version of the method. True False
True
Is the following statement true or false? In symmetric encryption and decryption, the key must be distributed beforehand. True False
True
Is the following statement true or false? Using for loop, each execution of the loop will read a line from the file into a string. True False
True
Is this statement true or false? In MySQL, a command normally consists of SQL statement followed by a semicolon True False
True
Is this statement true or false? When debugging in PyCharm (or Visual Studio) for Python programming, if you want to see what your code does line by line, there's no need to put a breakpoint on every line, you can step through your code. True False
True
Is this statement true or false? When debugging in PyCharm (or Visual Studio) for Python programming, you can enable Python console in the debugging Console. In this mode, you can enter some commands and expressions. For example, you can modify variable values. True False
True
It the following statement true or false? "From a function's perspective, a parameter is the variable listed inside the parentheses in the function definition, and an argument is the value that is sent to the function when it is called." True False
True
Length_Of_Rope and length_of_rope are two different variables in Python. This statement is _____. True False
True
The cursor() from a MySQLConnection object returns an object that can execute operations such as SQL statements. Cursor objects interact with the MySQL server. Is this statement true or false? True False
True
To access MySQL with Python, the connect() constructor creates a connection to the MySQL server and returns a MySQLConnection object. Is this statement true or false? True False
True
What is the output of the following code block? class Person: def __init__(self,fname,lname): self.firstname = fname self.lastname = lname def printname(self): print(self.firstname,self.lastname) class Student(Person): def __init__(self,fname,lname,age): self.firstname = fname self.lastname = lname self.Age = age def printage(self): print(self.Age) Tom=Student("Tom","Ray",25) print(isinstance(Tom,Person)) True False
True
If we define a set: myset = {'Apples', 'Bananas', 'Oranges'}, what will appear if we enter: myset[0] TypeError: 'set' object does not support indexing 'Apples'
TypeError: 'set' object does not support indexing
The output of the following codes is _______________. def changeme(mylist ): mylist.append([1,2,3,4]); print("Values inside the function: ", mylist) return list = [10,20,30]; changeme(list ); print("Values outside the function: ", list) Values inside the function: [10, 20, 30, [1, 2, 3, 4]] Values outside the function: [10, 20, 30, [1, 2, 3, 4]] Values inside the function: [10, 20, 30, [1, 2, 3, 4]] Values outside the function: [10, 20, 30] Values inside the function: [10, 20, 30] Values outside the function: [10, 20, 30, [1, 2, 3, 4]] Values inside the function: [10, 20, 30] Values outside the function: [10, 20, 30]
Values inside the function: [10, 20, 30, [1, 2, 3, 4]] Values outside the function: [10, 20, 30, [1, 2, 3, 4]]
The output of the following codes is _______________. def printinfo(var1, var2): print("var1: ", var1) print(var2: ",var2) return; printinfo(var2=50, var1="miki" ); Var1: miki Var2: 50 Var1: miki Var2: miki Var1: 50 Var2: 50 Var1: miki Var2: 50 Var1: 50 Var2: miki
Var1: miki Var2: 50
In the following function, _____ is applied to function arguments. def add_many_number(num1,*num_tuple): sum=0 sum=sum+num1 for num in num_tuple: sum=sum+num return(sum) Arbitrary keyword arguments Keyword arguments Required arguments Default arguments Variable-length arguments
Variable-length arguments
__________ in Tkinter are the elements of GUI application which provides various controls (such as Labels, Buttons, ComboBoxes, CheckBoxes, MenuBars, RadioButtons and many more) to users to interact with the application Widgets Controls Windows Elements
Widgets
All of the following are correct regarding scripting languages, except _____. Dynamically typed ( The type of a variable can be changed during the execution of the program) Scripting languages are often used to combine the functionality of other programs. They act as glue. Interpreted (no compilation step) You cannot directly use a variable. You must declare it first.
You cannot directly use a variable. You must declare it first.
^ Matches beginning of a line and beginning of string. What is the output of the following codes? import re ms= '''Tom 90\nMike 80\nHuang 96''' name= re.findall("^\w+",ms, re.MULTILINE) print(name) ['Tom','Mike','Huang'] ['Tom'] ['Tom 90\nMike 80\nHuang 96'] []
['Tom','Mike','Huang']
"\w" matches any alphanumeric character; "\W" any non-alphanumeric character. "\b" matches a word boundary; "\B" matches a character that is not a word boundary. What is the output of the following code? s= "He is the man's father and he is also a teacher! " word=re.findall("\\bhe\\b",s) print(word) ['he', 'he', 'he', 'he'] ['\\bhe\\b'] ['he'] ['he', 'he']
['he']
$ Matches end of a line and end of a string. Escape \ is to change back to the original meaning. What is the output of the following codes? S="He has {2+50}=70$ and his father has 1000" extr=re.findall("\{\d+\+\d+\}=\d+\$",S) print(extr) ['{2+50}=70$'] ['{2+50}=70'] ['1000'] []
['{2+50}=70$']
Read the following Python codes: l1=[1,2,3] l2=l1 l2[0]=10 print(l1) What is the output? Traceback error [1,2,3] [10,2,3]
[10,2,3]
_____ matches any one of a list of characters x;_____ matches any single character; ______ matches zero or more x; ______ matches one or more x. dot ., [x], x+, x* [x], dot ., x*, x+ dot ., [x], x*, x+ [x], dot ., x+, x*
[x], dot ., x*, x+
Python is sensitive to end of line stuff. To make a line continue, which symbol should be used? _____. ! # . \ -
\
Note: '\d' matches any digit; '\D' matches any non-digit. A student's username is composed of his/her first name, last name, a dash and order number, please fill in blanks to extract them. username="Knappen_Michell_01" order_number=re.findall('_____', username) # return ['01'] Name_with_dash=re.findall('_____',username) # ['Knappen_Michell_'] name=re.findall('_____',name_with_dash) # ['Knappen', 'Michell'] print(order_number[0],name[0],name[1]) # 01 Knappen Michell \D+, \d+, [A-Z][a-z]+ \D+, \d+, [A-Z]+ \d+, \D+, [A-Z][a-z]+ \w+, \D+, [A-Z][a-z]+
\d+, \D+, [A-Z][a-z]+
'\s' matches any whitespace character; '\S' any non-whitespace character. Notes: A space, a tab(\t), a carriage return(\r), a new line(\n) are all white spaces. Fill in the blank to extract ['3\t\n68', '78 6'] s="This thing happen 45 years ago or 6 years ago. I don't know. He told me it is 1000 years ago! 3\t\n68 year later, he will know 78 6 and he will come! " txt_d=re.findall('_____',s) print(txt_d) \s+\d+\s+ \d+\d+\s+ \d+\s+\d+ \s+\d+\d+
\d+\s+\d+
See the following code block. In order to hide the small image in the cover image for image stenography, the small image should be converted into _____ ( small_image_data_type) . img1 = stepic.encode(cover_image,small_image_data_type) img1.save('hidden_small_butterfly.PNG', 'PNG') a list a bytes sequence Any of them a string
a bytes sequence
What two requirements are needed for secure use of symmetric encryption? information and key algorithm and key algorithm and information
algorithm and key
Fill in the blank in the following code block. The program will insert multiple records into the table. import mysql.connector db_connection = mysql.connector.connect( host="localhost", user="root", passwd="mysqlpass", database="my_first_db" ) db_cursor = db_connection.cursor() student_sql_query = "INSERT INTO student(id,name) VALUES (%s, %s)" val= [ ('02', 'Tang'), ('03', 'Rapples'), ('04', 'Moain'), ('05', Michael')] #Execute cursor and pass query as well as student data db_cursor. _________(student_sql_query,val) db_connection.commit() print(db_cursor.rowcount, "Record Inserted") executemany execute insert
executemany
Fill in the blank in the following code block. The program will return the first row of the result. import mysql.connectormydb = mysql.connector.connect( host="localhost", user="root", passwd="mysqlpass", database="my_first_db" ) mycursor = mydb.cursor()mycursor.execute("SELECT * FROM student")myresult = mycursor._________()print(myresult) fetchall commit fetchone
fetchone
Read the Python codes: t=('a','b','c') type(t) type() above is a _____ neither of the answers function method
function
In image formats, properties of images such width and height are stored in the ______________ header pixel data
header
Regarding the "try...except..." suite, which of the following statements is wrong? none of the above the try suite contains code that we want to monitor for errors during its execution. if no special handler exists, Python handles it, meaning the program halts and with an error message as we have seen so many times if an error occurs anywhere in that try suite, Python looks for a handler that can deal with the error.
none of the above
Select the select functions/ modules for the following code block: #Print out all directories, sub-directories and files with os.walk() import _____ for root, dirs, files in ______('c:\\MyPythonDir'): print(root) print(dirs) print(files) os, os.walk subprocess, subprocess.mkdir os, os.mkdir subprocess, subprocess.walk
os, os.walk
The method "display" in the following code block is an empty method. Please select an appropriate key word to fill in the blank. # define a class class person: Name ="" Age =0 def set(self,name,age): self.Name=name self.Age =age def display(self): ________ # create a object Tom =person() Tom.set("Tom Ray", 55) Tom.display() # nothing done pass empty break continue
pass
Please select the correct file access modes. ___: Opens a file for reading, error if the file does not exist; ___: Opens a file for appending, creates the file if it does not exist; ___: Opens a file for writing, creates the file if it does not exist; ___: Creates the specified file, returns an error if the file exists. w, a, r, x r, a, x, w r, w, a, x r, a, w, x
r, a, w, x
Fill in the blank: # encryption from cryptography.fernet import Fernet #read the data from a file input_file = 'butterfly.jpg' # could be any file output_file = 'butterfly.encrypted' with open(input_file, '_______') as f: data = f.read() # Read the bytes of the input file #read the key from a file file = open('key_file.key', '_____') key = file.read() file.close() # encryption fernet = Fernet(key) encrypted = fernet.encrypt(data) rb, rt rb, rb rt, rb rt, rt
rb, rb
Chromatic (color) images for digital image display have three color components ___________________ red, green, blue black, white, gray cyan, magenta, yellow
red, green, blue
Least Significant Bit Steganography is to use the most _______ bit to embed the secret message middle left right
right
In MySQL, we can run the command "__________" to show all the available databases. show databases show tables
show databases
In the Python re module, the function _____ returns a list where the string has been split at each match split findall sub search
split
Select the select functions/ modules for the following code block: # Launch windows application. import _______ _______("notepad.exe") os, os.run subprocess, subprocess.execute subprocess, subprocess.run os, os.execute
subprocess, subprocess.run
In MySQL, we can enter the command "_______" to access / change database select [database_name] use [database_name] show databases
use [database_name]
About two kinds of attributes, 1) __________ are variable owned by a particular instance of a class. Each instance has its own value for it. These are the most common kind of attributes. 2) __________ are owned by the class as a whole. All class instances share the same value for it. They are good for (1) class-wide constants and (2) building counter of how many instances of the class have been made. class attributes, data attributes data attributes, data attributes data attributes, class attributes class attributes, class attributes
data attributes, class attributes
A _________________ (event handler) is a function or method that executes when the user clicks the button. user function interaction function callback function system call
callback function
In Tkinter, the _______________ is a rectangular area intended for drawing pictures or other complex layouts. You can place graphics, text, widgets, or frames on it. canvas frame panel label
canvas