Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to open the CSV file for reading.
Selenium Python
with open('testdata.csv', [1]) as file: reader = csv.reader(file) for row in reader: print(row)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'w' or 'a' mode which are for writing or appending, not reading.
✗ Incorrect
The mode 'r' opens the file for reading, which is needed to read test data from CSV.
2fill in blank
mediumComplete the code to import the module needed to read CSV files.
Selenium Python
[1] with open('testdata.csv', 'r') as file: reader = csv.reader(file) for row in reader: print(row)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated modules like os or json.
✗ Incorrect
The csv module is needed to read CSV files in Python.
3fill in blank
hardFix the error in the code to read CSV data and print the first column of each row.
Selenium Python
with open('testdata.csv', 'r') as file: reader = csv.reader(file) for row in reader: print(row[1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses or braces which cause syntax errors.
✗ Incorrect
To access the first element of a list in Python, use square brackets with index 0.
4fill in blank
hardFill both blanks to read CSV data into a list of dictionaries using DictReader.
Selenium Python
with open('testdata.csv', [1]) as file: reader = csv.[2](file) data = [row for row in reader] print(data)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using write mode or csv.reader instead of DictReader.
✗ Incorrect
Open the file in read mode 'r' and use csv.DictReader to read rows as dictionaries.
5fill in blank
hardFill all three blanks to read CSV data and assert the first row's 'username' is 'admin'.
Selenium Python
with open('testdata.csv', [1]) as file: reader = csv.DictReader(file) rows = list(reader) assert rows[[2]]['[3]'] == 'admin'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong file mode, wrong index, or wrong dictionary key.
✗ Incorrect
Open file in read mode 'r', access first row with index 0, and check 'username' key equals 'admin'.