Skip to content

Instantly share code, notes, and snippets.

@theArjun
Last active April 27, 2019 17:52
Show Gist options
  • Select an option

  • Save theArjun/ba9dcea51447eb158a087bfd2d0a6ef2 to your computer and use it in GitHub Desktop.

Select an option

Save theArjun/ba9dcea51447eb158a087bfd2d0a6ef2 to your computer and use it in GitHub Desktop.
Mock Data for Name, Address and Salary

✍ Arjun Adhikari, April 26, 2019

Question

A data tile "emp.txt" contains name, address and salary of 30 employees. Write a program to display only those records who are from "Kathmandu".

Output

In Java

Java Output

In Python

Python Output

Mock data for Testing
Meyer Kathmandu 9160
Ashlie Ladoeiro 57383
Brit Kathmandu 9002
Lovell Dukuh 50
Bradan Kathmandu 5215
Uriah Strawberry 3961
Deanna Barakani 595
Trix Kathmandu 12
Heath Rejowinangun 628
Binni Kathmandu 7
Harv Ängelholm 0558
Winnifred Kostakioí 38
Harmonie Liuji 61982
Jolynn Kathmandu 41
Paddie Santa 2107
Daloris Kathmandu 6806
Jerry Pamoyanan 61
Isak Lamentin 679
Benetta Singosari 7494
Rab Cikomara 6818
Archer Kathmandu 54
Amalita Seredyna-Buda 0
Cart Kathmandu 71
Philippa Erdaocha 82530
Jeffie Wuma 97226
Frannie Kathmandu 8
Rozalie Oklahoma 666
Davon Singgit 50225
Towny Sahnaiya 0
Henka Kathmandu 027
// Java Program
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
class Kathmandu {
public static void main(String[] args) {
try {
BufferedReader br = new BufferedReader(new FileReader("emp.txt"));
String line = br.readLine();
while (line != null) {
if (line.contains("Kathmandu")) {
System.out.println(line);
}
line = br.readLine();
}
br.close();
} catch (IOException exc) {
System.out.println("Error While opening file.");
}
}
}
# Python Program
if __name__ == "__main__":
try:
my_file = open('emp.txt', 'r')
for line in my_file:
if line.count('Kathmandu') != 0:
print(line, end='')
my_file.close()
except FileNotFoundError:
print("Error while opening file.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment