1/183
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Which of the following is a valid identifier?
(a) $343
(b) def
(c) mac_radius
(d) eight&nine
(c) mac_radius
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.
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
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
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
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
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
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
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
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
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
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
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
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]
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):
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.
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;
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;
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';
If you want to select all the fields available in the table, use the following syntax...
SELECT * FROM table;
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;
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;
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 %';
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';
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');
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));
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);
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;
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;
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;
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;
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;
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);
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;
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;
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;
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;
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;
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
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
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
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
LOOK AT SQLITE THINGS
the ability to communicate between multiple machines
networking
what are methods of network programming available in Python?
sockets, socketserver
most basic networking model
client-server
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
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
simply an endpoint of communication, provide an abstraction for the details of communication
socket
can interface with a socket object
application
after you make the socket you'll have to connect to _______________
another socket
socket.socket( [ family, [type] ] ) --> this creates a socket object
socket module
from socket import *
s = socket(AF_INET, SOCK_STREAM)
# or s = socket()
IPv4 TCP socket
this function creates a connection between the socket s and the specified address addr
s.connect(addr)
a tuple containing the host name (as a string) and port number (as an int)
addr argument
(s.connect(addr))
this function sends a string to the address to which the socket is currently connected
s.send(string)
the return value of this function is the number of bytes sent
s.send(string)
no guarantee that the whole message was sent with this function
s.send(string)
receives and returns up to bufsize bytes of data from the address to which the socket is currently connected
s.recv(bufsize)
closes the connection (sockets are also automatically closed when garbage collected)
s.close()
The connect(), send(), recv() and close() functions are all we need to write a simple...
TCP client
binds the socket object to an address addr
(as before: addr is a tuple containing the hostname and port)
s.bind(addr)
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)
returns a string containing the local machine's primary public hostname
socket.gethostname()
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()
connect when they need and close after a transaction ( connect(), send() and recv(), close() )
clients
connect(), send() and recv(), close()
most important functions
listen for connections and communicate with each client using a new, unique socket object
( bind(), listen(), loop: accept(), send() and recv(), close() )
servers
bind(), listen(), loop: accept(), send() and recv(), close()
main functions
useful utility function:
socket.gethostbyname("www.python.org"
returns IP
useful utility function:
socket.gethostbyaddr("82.94.237.218")
returns name
this function may receive fewer bytes than the specified max; returns an empty
string when the connection is closed.
s.recv(max)
blocks until all data has been transmitted, none is returned on success
s.sendall(string)
this module can be used by including the import SocketServer statement at the top of your module.
SocketServer
creates a TCP/IP server object
SocketServer.TCPServer()
creates a UDP/IP server object
SocketServer.UDPServer()
creates a TCP server using Unix domain sockets
SocketServer.UnixStreamServer()
creates a UDP server using Unix domain sockets
SocketServer.UnixDatagramServer()
first step to creating a TCP/IP server is to create a request handler class which inherits from...
BaseRequestHandler
( SocketServer.BaseRequestHandler() )
the socket connected to the client for SocketServer
BaseRequentHandler.request
the address of the client for SocketServer
BaseRequestHandler.client_address
In ______________, our new server object has the following attributes available:
server.server_address and server.request_queue_size
SocketServer
the address on which the server is listening
server.request_queue_size
the number of incoming connections to
queue, default is 5
server.server_address
web application framework written in Python
python
installed through pip
flask
(pip install Flask)
how to associate a URL with a function/tells the application which URL should call the associated function, a decorator
route
( app.route('/') )
takes the name of the current module as the parameter
flask constructor
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() )
127.0.0.1
localhost IP address
several ways to make a HTTP REQUEST, such as ________ and _________
GET, POST
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
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
Where is the placeholder below?
{{ name }}
a database management software that is available with a python installation
sqlite
How do you create a sqlite database on the terminal?
sqlite3 database.db
What is Kerckhoffs' Principle?
The adversary knows all details of the encryption function except the secret key
--> 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
remains by far the most widely used of the two types of encryption
symmetric encryption
medium through which the message is transmitted
channel