Computer Science
Sonia was writing a code to insert multiple rows in the cust.csv file. By mistake her younger sister removed some parts of it. Now she is totally confused about used module and other options:
from csv import writer
with ............... ("cust.csv", "a", newline = "\n") as f: #line 1
dt = writer(...............) #line 2
while True: #line 3
sno= int (input ("Enter Serial No: ") )
cust_name = input ("Enter customer name: ")
city = input ("Enter city: ")
amt = int (input ("Enter amount: ") )
dt. ............... ( [sno, cust name, city, amt] ) #line 4
print ("Record has been added.")
print ("Want to add more record?Type YES!!!")
ch = input() #line 5
ch = ch.upper()
if ch=="YES":
print("*")
else:
break
Attempt any 4 out of the given questions:
(i) Name the method Sonia should use in Line 1.
(ii) Which object Sonia should use to connect the file in Line 2?
(iii) What is the use of Line 3?
(iv) Name the method she should use in Line 4.
(v) What is the use of Line 5?
Answer
(i) Sonia should use the "open" method to connect to the "cust.csv" file in append mode.
(ii) Sonia should use the file object "f" to connect to the file.
(iii) Line 3 starts a while loop using while True:. This creates an infinite loop that allows Sonia to repeatedly input customer data and add records to the CSV file until she chooses to stop.
(iv) Sonia should use the "writerow" method to write a single row (list of values) to the CSV file.
(v) Line 5 reads the Sonia's input for whether she want to add more records to the CSV file.
Related Questions
A binary file "salary.Dat" has structure [employee id, employee name, salary]. Write a function countrec() in Python that would read contents of the file "salary.Dat" and display the details of those employees whose salary is above 20000.
A departmental store "ABC" is considering maintaining their inventory using SQL to store data and maintain basic transactions. As a database manager, Mehak has to create two tables as Customer & Transaction:
Table: CUSTOMER
CNo CNAME ADDRESS 101 Richa Jain Delhi 102 Surbhi Sinha Chennai 103 Lisa Thomas Bengaluru 104 Imran Ali Delhi 105 Roshan Singh Chennai Table: TRANSACTION
Dept CNO AMOUNT TYPE DOT T001 101 1500 Credit 2017-11-23 T002 103 2000 Debit 2017-05-12 T003 102 3000 Credit 2017-06-10 1004 103 12000 Credit 2017-09-12 T005 101 1000 Debit 2017-09-05 (i) Identify the attribute best suited to be declared as a Primary key in customer table.
(ii) Help Mehak to display details of all transactions of TYPE Credit from Table TRANSACTION.
(iii) Mehak wants to display all CNO, CNAME and DOT (date of transaction) of those CUSTOMERS from tables CUSTOMER and TRANSACTION who have done transactions more than or equal to 2000 for the Balance Sheet.
(iv) Mehak wants to display the last date of transaction (DOT) from the table TRANSACTION for the customer having CNO as 103. Which command will she use?
To provide telemedicine facility in a hilly state, a computer network is to be set up to connect hospitals in 6 small villages (V1, V2, …, V6) to the base hospital (H) in the state capital. This is shown in the following diagram.

No village is more than 20 km away from the state capital. Imagine yourself as a computer consultant for this project and answer the following questions with justification:
(i) Out of the following, what kind of link should be provided to set up this network: Microwave Link, Radio Link, Wired Link?
(ii) Many a time doctors at the village hospital have to consult senior doctors at the base hospital. How should they contact them—through email, SMS, telephone or video conference?
(iii) Out of SMTP and POP3, which protocol is used to receive emails?
(iv) Expand the following terms:
(a) VoIP
(b) HTTPS
(v) Mention any two advantages of using Star topology.
Write the output of the code given below:
p=8 def sum(q=5, r=6) : p=(r+q)**2 print(p, end= '#') sum(p) sum(r=3,q=2)