-
Notifications
You must be signed in to change notification settings - Fork 1
/
MOCKQ8DBMS.py
46 lines (33 loc) · 1.32 KB
/
MOCKQ8DBMS.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#Write a Python program to print the ISBN numbers of books which are published in a given year. Here, the year is obtained as the value of function L(x) (given after the sample output) at x. You have to read the value of x from the input file "number.txt", and use it to find the value of L(x). Your program must assume that the file number.txt resides in the same folder as your Python program.
#You have to iterate through the list and print each value separately as shown in the output below:
#9789352921171
#9789351343202
#9789353333380
#The line function is given below:
#L2(x) = 2000 + 4*x
import sys
import os
import psycopg2
file = open("number.txt","r")
x = file.read()
def L(x):
return (2000+(4*x))
year = L(int(x))
try:
connection = psycopg2.connect(
database = sys.argv[1],
user = os.environ.get('PGUSER'),
password = os.environ.get('PGPASSWORD'),
host = os.environ.get('PGHOST'),
port = os.environ.get('PGPORT'))
cursor = connection.cursor()
query = "select ISBN_no from book_catalogue where year = '{}'".format(year)
cursor.execute(query)
result = cursor.fetchall()
for res in result:
print(res[0])
cursor.close()
except(Exception, psycopg2.DatabaseError) as error:
print(error)
finally:
connection.close