Q8Single correct3 Marks1 Sep 2024
Consider the file `countries.txt` given below, also consider the python file both in the same directory. What will be the output of the code below?
File `countries.txt`:
IND-New Delhi-+91
USA-Washington D.C.-+1
RU-Moscow-+7
CHN-Beijing-+86
BR-Brasilia-+55
The separator used in `countries.txt` is `-` which is same as the one used in `.split()` method in python code.
Code Snippet
file_path = "countries.txt"
file = open(file_path, "r")
```
file_path = "countries.txt"
file = open(file_path, "r")
for line in file:
modified_line = line.strip()
modified_line = modified_line.split('-')
print(modified_line[0], "|", modified_line[2])
file.close()
```