COP4521 Midterm

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/183

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

184 Terms

1
New cards

Which of the following is a valid identifier?

(a) $343

(b) def

(c) mac_radius

(d) eight&nine

(c) mac_radius

2
New cards

Analyze the following statement:

sum = 0

for d in range(0, 10, 0.1):

sum += sum + d

(a) The program has a syntax error because the range function cannot have three arguments.

(b) The program has a syntax error because the arguments in the range must be integers.

(c) The program runs in an infinite loop.

(d) The program runs fine.

(b) The program has a syntax error because the arguments in the range must be integers.

3
New cards

What is the output of the following code?

x = 0

while x < 4:

x = x + 1

A. x is 0

B. x is 1

C. x is 2

D. x is 3

E. x is 4

E. x is 4

4
New cards

Analyze the following code.

count = 0

while count < 100:

# Point A

print("Welcome to Python!")

count += 1

# Point B

# Point C

Select the following that are true statements:

A. count < 100 is always True at Point A

B. count < 100 is always True at Point B

C. count < 100 is always False at Point B

D. count < 100 is always True at Point C

E. count < 100 is always False at Point C

A and E

5
New cards

How many times will the following code print "Welcome to Python"?

count = 0

while count < 10:

print("Welcome to Python")

A. 8

B. 9

C. 10

D. 11

E. infinite number of times

E. infinite number of times

6
New cards

What will be displayed when the following code is executed?

number = 6

while number > 0:

number -= 3

print(number, end = ' ')

A. 6 3 0

B. 6 3

C. 3 0

D. 3 0 -3

E. 0 -3

C. 3 0

7
New cards

Which of the following loops prints "Welcome to Python" 10 times?

A:

for count in range(1, 10):

print("Welcome to Python")

B:

for count in range(0, 10):

print("Welcome to Python")

C:

for count in range(1, 11):

print("Welcome to Python")

D:

for count in range(1, 12):

print("Welcome to Python")

A. BD

B. ABC

C. AC

D. BC

E. AB

D. BC

8
New cards

The function range(5) return a sequence ______________.

A. 1, 2, 3, 4, 5

B. 0, 1, 2, 3, 4, 5

C. 1, 2, 3, 4

D. 0, 1, 2, 3, 4

D. 0, 1, 2, 3, 4

9
New cards

Which of the following function returns a sequence 0, 1, 2, 3?

(can select multiple functions)

A. range(0, 3)

B. range(0, 4)

C. range(3)

D. range(4)

B and D

10
New cards

Which of the following function is incorrect?

(can select multiple functions)

A. range(0, 3.5)

B. range(10, 4, -1)

C. range(1, 3, 1)

D. range(2.5, 4.5)

E. range(1, 2.5, 4.5)

A, D, and E

11
New cards

Which of the following loops correctly computes 1/2 + 2/3 + 3/4 + ... + 99/100?

A:

sum = 0

for i in range(1, 99):

sum += i / (i + 1)

print("Sum is", sum)

B:

sum = 0

for i in range(1, 100):

sum += i / (i + 1)

print("Sum is", sum)

C:

sum = 0

for i in range(1.0, 99.0):

sum += i / (i + 1)

print("Sum is", sum)

D:

sum = 0

for i in range(1.0, 100.0):

sum += i / (i + 1)

print("Sum is", sum)

A. BCD

B. ABCD

C. B

D. CDE

E. CD

C. B

12
New cards

The following loop displays _______________.

for i in range(1, 11):

print(i, end = " ")

A. 1 2 3 4 5 6 7 8 9

B. 1 2 3 4 5 6 7 8 9 10

C. 1 2 3 4 5

D. 1 3 5 7 9

E. 2 4 6 8 10

B. 1 2 3 4 5 6 7 8 9 10

13
New cards

What is the output for y?

y = 0

for i in range(0, 10):

y += i

print(y)

A. 10

B. 11

C. 12

D. 13

E. 45

E. 45

14
New cards

What is the output of the following code?

l1=[10, 20, 30]

l2=[-10, -20, -30]

l3=[x+y for x, y in zip(l1, l2)]

print(l3)

a) Error

b) 0

c) [-20, -60, -80]

d) [0, 0, 0]

d) [0, 0, 0]

15
New cards

Which of the following is the correct definition of an instance method, where 'bar' is an argument of the method?

a) def foo($self, bar):

b) def foo(bar):

c) def foo(self, bar):

d) def __foo__(bar):

e) None of the above.

c) def foo(self, bar):

16
New cards

Which of the following statement is not true?

class Point:

x = 0

y = 0

def __init__(self, x, y):

Point.x = x

Point.y = y

self.x = x

self.y = y

>>> p1 = Point(1,2)

>>> p2 = Point(3,4)

>>> p2.x = 2

a) Point.x equals to 3 and Point.y equals to 4.

b) Point.x equals to 1 and Point.y equals to 2.

c) p1.x equals to 1 and p1.y equals to 2.

d) p2.x equals to 2 and p2.y equals to 4.

e) None of the above.

b) Point.x equals to 1 and Point.y equals to 2.

17
New cards

Write a SQL statement to display specific columns like name and commission for all the salesman

Sample Table: salesman

Column Names: salesman_id, name, city, commission

SELECT name, commission FROM salesman;

18
New cards

Write a SQL statement to find the unique salespeople ID. Return salesman_id.

Sample Table: orders

Column Names: ord_no, purch_amt, od_date, customer_id, salesman_id

SELECT DISTINCT salesman_id FROM orders;

19
New cards

Write a SQL query to find the salespeople who lives in the City of 'Paris'. Return salesperson's name, city.

Sample Table: salesman

Column Names: salesman_id, name, city, commission

SELECT name, city FROM salesman WHERE city='Paris';

20
New cards

If you want to select all the fields available in the table, use the following syntax...

SELECT * FROM table;

21
New cards

From the following table, write a SQL query to find those customers whose grade is 200. Return customer_id, cust_name, city, grade, salesman_id.

Sample Table: customer

Column Names: customer_id, cust_name, city, grade, salesman_id

SELECT *FROM customer WHERE grade=200;

22
New cards

From the following table, write a SQL query to find the Nobel Prize winners in 'Chemistry' between the years 1965 to 1975. Begin and end values are included. Return year, subject, winner, and country

Sample Table: nobel_win

Column Names: year, subject, winner, country, category

SELECT year, subject, winner, country FROM nobel_win WHERE subject='Chemistry' AND year>=1965 AND year<=1975;

23
New cards

From the following table, write a SQL query to find the details of the winners whose first name matches with the string 'Louis'. Return year, subject, winner, country, and category.

Sample Table: nobel_win

Column Names: year, subject, winner, country, category

SELECT *FROM nobel_win WHERE winner LIKE 'Louis %';

24
New cards

From the following table, write a SQL query to find the Nobel Prize winners in 'Physics' since the year 1950. Return winner.

Sample Table: nobel_win

Column Names: year, subject, winner, country, category

SELECT winner FROM nobel_win WHERE year>=1950 AND subject='Physics';

25
New cards

Write a SQL query to show all details of the Prime Ministerial winners after 1972 of Menachem Begin and Yitzhak Rabin.

Sample Table: nobel_win

Column Names: year, subject, winner, country, category

SELECT * FROM nobel_win WHERE year>1972 AND winner IN ('Menachem Begin', 'Yitzhak Rabin');

26
New cards

From the following table, write a SQL query to combine the winners in Physics, 1970 and in Economics, 1971. Return year, subject, winner, country, and category.

Sample Table: nobel_win

Column Names: year, subject, winner, country, category

SELECT FROM nobel_win WHERE (subject ='Physics' AND year=1970) UNION (SELECT FROM nobel_win WHERE (subject ='Economics' AND year=1971));

27
New cards

From the following table, write a SQL query to find the cheapest item(s). Return pro_name and, pro_price.

Sample Table: item_mast

Column Names: pro_id, pro_name, pro_price, pro_company

SELECT pro_name, pro_price FROM item_mast WHERE pro_price = (SELECT MIN(pro_price) FROM item_mast);

28
New cards

From the following table, write a SQL query to calculate average price of the items of each company. Return average price and company code.

Sample Table: item_mast

Column Names: pro_id, pro_name, pro_price, pro_company

SELECT AVG(pro_price), pro_company FROM item_mast GROUP BY pro_com;

29
New cards

From the following table, write a SQL query to select a range of products whose price is in the range Rs.200 to Rs.600. Begin and end values are included. Return pro_id, pro_name, pro_price, and pro_company.

Sample Table: item_mast

Column Names: pro_id, pro_name, pro_price, pro_company

SELECT * FROM item_mast WHERE pro_price BETWEEN 200 AND 600;

30
New cards

From the following table, write a SQL query to display the pro_name as 'Item Name' and pro_priceas 'Price in Rs.'

Sample Table: item_mast

Column Names: pro_id, pro_name, pro_price, pro_company

SELECT pro_name as "Item Name", pro_price AS "Price in Rs." FROM item_mast;

31
New cards

From the following table, write a SQL query to find the items whose prices are higher than or equal to $250. Order the result by product price in descending, then product name in ascending. Return pro_name and pro_price.

Sample Table: item_mast

Column Names: pro_id, pro_name, pro_price, pro_company

SELECT pro_name, pro_price FROM item_mast WHERE pro_price >= 250 ORDER BY pro_price DESC, pro_name;

32
New cards

From the following table, write a SQL query to find the customers who belong to either the city 'New York' or not have a grade above 100. Return customer_id, cust_name, city, grade, and salesman_id.

Sample Table: customer

Column Names: customer_id, city, grade, salesman_id

SELECT * FROM customer WHERE city = 'New York' OR NOT grade>100;

33
New cards

From the following table, write a SQL query to find those customers who belong to neither the 'New York' city nor their grade value exceeds 100. Return customer_id, cust_name, city, grade, and salesman_id.

Sample Table: customer

Column Names: customer_id, city, grade, salesman_id

SELECT * FROM customer WHERE NOT (city = 'New York' OR grade>100);

34
New cards

From the following table, write a SQL query to calculate total purchase amount of all orders. Return total purchase amount.

Sample Table: orders

Column Names: ord_no, purch_amt, ord_date, customer_id, salesman_id

SELECT SUM (purch_amt) FROM orders;

35
New cards

From the following table, write a SQL query to count the number of unique salespeople. Return number of salespeople.

Sample Table: orders

Column Names: ord_no, purch_amt, ord_date, customer_id, salesman_id

SELECT COUNT (DISTINCT salesman_id) FROM orders;

36
New cards

From the following table, write a SQL query to count the number of customers. Return number of customers.

Sample Table: customer

Column Names: customer_id, city, grade, salesman_id

SELECT COUNT(*) FROM customer;

37
New cards

From the following table, write a SQL query to find the number of customers who got at least a grade for his/her activity. (some people did not get a grade)

Sample Table: customer

Column Names: customer_id, city, grade, salesman_id

SELECT COUNT (ALL grade) FROM customer;

38
New cards

From the following table, write a SQL query to find the highest grade of the customers for each of the city. Return city, maximum grade.

Sample Table: customer

Column Names: customer_id, city, grade, salesman_id

SELECT city,MAX(grade) FROM customer GROUP BY city;

39
New cards

What is the difference between NoSQL and RDBMS?

- NoSQL is a distributed database while RDBMS is a relational database

- NoSQL has dynamic schema, RDBMS uses static and predefined schemas

- NoSQL is best suited for hierarchical data storage, RDBMS is not suited for hierarchical data storage

- NoSQL is not so good for complex queries, RDBMS is best suited for complex queries

- NoSQL is horizontally scalable, RDBMS is vertically scalable

- NoSQL uses key-value pairs and RDBMS is table-based

- NoSQL follows CAP theorem and RDBMS follows ACID properties

40
New cards

What are the various advantages of NoSQL databases?

- handles large volumes of data at high speed

- multi-model (store unstructured, semi-structured, or structured data)

- easy to update schemas/fields

41
New cards

When should I use a NoSQL database instead of a relational database?

NoSQL databases were created to handle big data, multi-model data structures, availability for high traffic on a site

42
New cards

What are the challenges of using NoSQL?

NoSQL databases are less mature, less supportive, there's no advanced expertise, no reliability functions, developers have to implement code to make their systems more complex, NoSQL is not compatible with SQL

43
New cards

LOOK AT SQLITE THINGS

44
New cards

the ability to communicate between multiple machines

networking

45
New cards

what are methods of network programming available in Python?

sockets, socketserver

46
New cards

most basic networking model

client-server

47
New cards

the client sends out a request to a server--the server processes the request and sends a response back to the client

client-server model

48
New cards

a web browser sending a request for a webpage to a webserver--the webserver processes the request and returns the webpage to the browser

classic example of a client-server model

49
New cards

simply an endpoint of communication, provide an abstraction for the details of communication

socket

50
New cards

can interface with a socket object

application

51
New cards

after you make the socket you'll have to connect to _______________

another socket

52
New cards

socket.socket( [ family, [type] ] ) --> this creates a socket object

socket module

53
New cards

from socket import *

s = socket(AF_INET, SOCK_STREAM)

# or s = socket()

IPv4 TCP socket

54
New cards

this function creates a connection between the socket s and the specified address addr

s.connect(addr)

55
New cards

a tuple containing the host name (as a string) and port number (as an int)

addr argument

(s.connect(addr))

56
New cards

this function sends a string to the address to which the socket is currently connected

s.send(string)

57
New cards

the return value of this function is the number of bytes sent

s.send(string)

58
New cards

no guarantee that the whole message was sent with this function

s.send(string)

59
New cards

receives and returns up to bufsize bytes of data from the address to which the socket is currently connected

s.recv(bufsize)

60
New cards

closes the connection (sockets are also automatically closed when garbage collected)

s.close()

61
New cards

The connect(), send(), recv() and close() functions are all we need to write a simple...

TCP client

62
New cards

binds the socket object to an address addr

(as before: addr is a tuple containing the hostname and port)

s.bind(addr)

63
New cards

tells the socket to begin listening for connections. The backlog argument specifies how many connections to queue before connections become refused (default is zero)

s.listen(backlog)

64
New cards

returns a string containing the local machine's primary public hostname

socket.gethostname()

65
New cards

passively waits until a connection is made, return value is a pair (conn, address)

where:

conn = new socket object

address = address bound to the socket on the other end of the connection

s.accept()

66
New cards

connect when they need and close after a transaction ( connect(), send() and recv(), close() )

clients

67
New cards

connect(), send() and recv(), close()

most important functions

68
New cards

listen for connections and communicate with each client using a new, unique socket object

( bind(), listen(), loop: accept(), send() and recv(), close() )

servers

69
New cards

bind(), listen(), loop: accept(), send() and recv(), close()

main functions

70
New cards

useful utility function:

socket.gethostbyname("www.python.org"

returns IP

71
New cards

useful utility function:

socket.gethostbyaddr("82.94.237.218")

returns name

72
New cards

this function may receive fewer bytes than the specified max; returns an empty

string when the connection is closed.

s.recv(max)

73
New cards

blocks until all data has been transmitted, none is returned on success

s.sendall(string)

74
New cards

this module can be used by including the import SocketServer statement at the top of your module.

SocketServer

75
New cards

creates a TCP/IP server object

SocketServer.TCPServer()

76
New cards

creates a UDP/IP server object

SocketServer.UDPServer()

77
New cards

creates a TCP server using Unix domain sockets

SocketServer.UnixStreamServer()

78
New cards

creates a UDP server using Unix domain sockets

SocketServer.UnixDatagramServer()

79
New cards

first step to creating a TCP/IP server is to create a request handler class which inherits from...

BaseRequestHandler

( SocketServer.BaseRequestHandler() )

80
New cards

the socket connected to the client for SocketServer

BaseRequentHandler.request

81
New cards

the address of the client for SocketServer

BaseRequestHandler.client_address

82
New cards

In ______________, our new server object has the following attributes available:

server.server_address and server.request_queue_size

SocketServer

83
New cards

the address on which the server is listening

server.request_queue_size

84
New cards

the number of incoming connections to

queue, default is 5

server.server_address

85
New cards

web application framework written in Python

python

86
New cards

installed through pip

flask

(pip install Flask)

87
New cards

how to associate a URL with a function/tells the application which URL should call the associated function, a decorator

route

( app.route('/') )

88
New cards

takes the name of the current module as the parameter

flask constructor

89
New cards

runs the application on the local development server; hostname defaults to localhost (127.0.0.1) and port number defaults to 5000

run method

( app.run() )

90
New cards

127.0.0.1

localhost IP address

91
New cards

several ways to make a HTTP REQUEST, such as ________ and _________

GET, POST

92
New cards

When a client (browser) requests a URL, it sends a _____________ to the server--The server then sends the resulting rendered HTML page as a HTTP RESPONSE.

HTTP request

93
New cards

In order to add information from the request/URL into the resulting HTML, we have to incorporate ____________ into the HTML files and place the files themselves into a folder called "____________"

placeholders, templates

94
New cards

Where is the placeholder below?

Hello {{ name }}

{{ name }}

95
New cards

a database management software that is available with a python installation

sqlite

96
New cards

How do you create a sqlite database on the terminal?

sqlite3 database.db

97
New cards

What is Kerckhoffs' Principle?

The adversary knows all details of the encryption function except the secret key

98
New cards

--> use a private key for both encrypting and decrypting

--> both the sender and the recipient use the same secret key to encode and decode the message

--> conceal the contents of blocks or streams of data, using the same private key as used for decrypting

symmetric encryption

99
New cards

remains by far the most widely used of the two types of encryption

symmetric encryption

100
New cards

medium through which the message is transmitted

channel