JavaScript isn't enabled in your browser, so this file can't be opened. Enable and reload.
Python Quiz on Pandas Read CSV
There are
20 questions based on Pandas Read CSV.
Sign in to Google
to save your progress.
Learn more
* Indicates required question
Q1. What does the following code print?
income = 1000
expense = 400
net = income - expense
print(f"Net income: ${net}")
*
4 points
Net income: $1400
Net income: $600
Net income: 600
$600
Q2. What will this Python code output?
revenue = 10000
expenses = 7500
profit = revenue - expenses
print("Net Profit:", profit)
*
4 points
Net Profit: 2500
Net Profit: 17500
Net Profit: 7500
Error
Q3. What does this Python dictionary access return?
patient = {"name": "Ali", "age": 35, "blood_type": "O+"}
print(patient["blood_type"])
*
4 points
35
Ali
O+
Error
Q4. What is the time complexity of the binary search algorithm?
*
4 points
O(n)
O(log n)
O(n²)
O(1)
Q5.
What will the following Python function return?
def grade(score):
return "Pass" if score >= 50 else "Fail"
print(grade(45))
*
4 points
Pass
Fail
Error
45
Q6. What does the following code print if industry.csv contains one industry name per line?
import csv
with open('industry.csv', newline='') as file:
reader = csv.reader(file)
rows = list(reader)
print(rows[0])
*
4 points
['Accounting/Finance']
Accounting/Finance
['Accounting', 'Finance']
An error is raised
Q7. What will this code output if industry.csv contains 44 industry names (one per line)?
import csv
with open('industry.csv', newline='') as file:
reader = csv.reader(file)
count = sum(1 for row in reader)
print(count)
*
4 points
40
42
44
46
Q8. What does this code do?
import csv
with open('industry.csv') as f:
reader = csv.reader(f)
for row in reader:
print(row[0])
*
4 points
Prints each character in the file
Prints all industry names line by line
Raises an IndexError
Writes to a new CSV file
Q9. What does the following code do?
import csv
with open('industry.csv') as f:
reader = csv.reader(f)
next(reader) # Skip header
for row in reader:
print(row[0])
*
4 points
Skips the first industry
Raises StopIteration
Skips every second line
Prints the file name
Q10. What does this code do?
import csv
with open('industry.csv', 'a', newline='') as f:
writer = csv.writer(f)
writer.writerow(['AI/ML'])
*
4 points
Overwrites the file
Appends a new industry at the end
Deletes the file
Replaces the first line
Q11. What will print(industry_list) display?
import csv
with open('industry.csv') as f:
reader = csv.reader(f)
industry_list = [row[0] for row in reader]
print(industry_list[:3])
*
4 points
First 3 characters of the first row
First 3 full industry names
All rows reversed
Raises an error
Q12. What does this code assume about the CSV file?
with open('industry.csv') as f:
reader = csv.DictReader(f)
for row in reader:
print(row['Industry'])
*
4 points
The file has no header
The file uses tab-delimiters
The first row must contain column names
The file is empty
Q13. What will this code do?
import csv
with open('industry.csv', 'w', newline='') as f:
writer = csv.writer(f)
writer.writerow(['Industry'])
writer.writerow(['Accounting/Finance'])
*
4 points
Appends to the file
Replaces all existing data with 2 rows
Skips the header
Raises an error
Q14. What will this code print?
import csv
with open('industry.csv') as f:
reader = csv.reader(f)
count = sum(1 for row in reader if 'Finance' in row[0])
print(count)
*
4 points
Total rows in the file
Number of industries containing the word "Finance"
Number of columns
Nothing
Q15. What does this code check?
import csv
with open('industry.csv') as f:
reader = csv.reader(f)
data = list(reader)
if not data:
print("File is empty")
*
4 points
Checks if the file is too big
Checks if file has no rows
Checks for duplicates
Always prints empty
Q16. What will this print?
import csv
with open('industry.csv') as f:
reader = csv.reader(f, delimiter=';')
for row in reader:
print(row)
*
4 points
Splits rows using semicolon ;
Splits rows using comma ,
Raises syntax error
Uses default delimiter
Q17. What is the result of this code?
import csv
with open('industry.csv') as f:
reader = csv.reader(f)
for i, row in enumerate(reader):
if i >= 5:
break
print(row[0])
*
4 points
Prints all rows
Prints nothing
Prints first 5 industries
Error: i is not defined
Q18. Why is the with open(...) statement used when handling CSV files?
*
4 points
It’s slower but easier
It avoids using csv.reader()
It automatically closes the file
It writes directly to the browser
Q19. What does this code do?
import csv
with open('industry.csv') as f:
reader = csv.reader(f)
blanks = [row for row in reader if not row or row[0].strip() == '']
print(len(blanks))
*
4 points
Counts all rows
Counts rows with no data
Prints blank string
Deletes blank rows
Q2O. What does this code do?
import csv
industries = [['Healthcare'], ['Education'], ['Technology']]
with open('industry.csv', 'w', newline='') as f:
writer = csv.writer(f)
writer.writerows(industries)
*
4 points
Appends 3 rows
Overwrites the file with 3 rows
Adds header only
Fails due to indentation
Submit
Clear form
Forms
This content is neither created nor endorsed by Google.
Report Abuse
Terms of Service
Privacy Policy
Help and feedback
Contact form owner
Help Forms improve
Report