AB0403 Revision Set II
AB0403 Revision Set II
AB0403 Revision Set II
(a.txt must be in the same folder as the .py file, if we only put “a.txt” in the open() function)
# Q2. If we PRINT the elements of s from Q1 to a file, one element at a time, what will happen? Do
you see extra empty lines?
# Q3. How do we remove the extra empty lines you see in Q2, if we still use print() function?
# Q4. If we WRITE the elements of s from Q1 to a file, one element at a time, what will happen?
Do you see extra empty lines?
'''
“C:\Users\...\Desktop\a.csv" contains below content with two empty lines at the end
Name,Age
HB,33
Jane,23
'''
# Q7. Does the code below work? What will the list look like?
import csv
s = []
with open("a.csv", "r") as f:
csv_pointer = csv.reader(f)
for each in csv_pointer:
s.append(each)
print(s)
# Q8. What will the file look like? Why are there empty lines between the 2 lines?
row = ["a","b","c"]
with open("b.csv", "w") as f:
csv_pointer = csv.writer(f)
csv_pointer.writerow(row)
csv_pointer.writerow(row)
# Q12. Given two tables t1 and t2, describe what happens when the following statement
executes?
select * from t1, t2;
# Q15. If a String to be stored in the database varies between 10 - 25 characters, what would be
the best data type for the table column?
# Q16. Consider the following table creation and data insertion statements.
create table manager (
manager_code int not null,
manager_name varchar(10));
What would the sequence of names be like for the following statement?
# Q17. Continue from the tables in qn 6, what would the following statement return?
select * from employee where exists (select * from manager);
# Q18. How can we modify the sub-query of the above statement to only return employees who
are managers?
# Q19. How can we find a String attribute that starts with the word 'Python'?
# Q20. Consider the following table creation and data insertion statements.
create table country_population (
country_name varchar(20),
continent varchar(15),
population int);