python programming

0 comments

Download test.txt from the link below

http://csit.udc.edu/~jkim/data/test.txt

#hid pid age gender

126774360 405498148 22 2

126774361 405498149 29 1

126774362 405498150 32 2

126774363 405498152 48 2

126774363 405498151 49 2

Figure 1. Example of the input file (i.e., test.txt)

For text.txt,

  • The file (i.e., test.txt) contains household id, person id, age, and gender for each person.
  • For gender, 1 and 2 represent male and female, respectively.
  • If persons have the same household id, they live together. For example, person ids 405498152 and 405498151 have the same household id 126774363 as shown in Figure 1.

Design a shell program (File name: person_female_30_50.sh)

  1. Read text.txt using a file descriptor (Use exec 3< $1 and read)
  2. Extract person ids corresponding to persons who are female, and more than 30 and less than 50 years old. (Use a loop)
  3. Store the extracted person ids to $2 indicating the second parameter. (Use exec 4> $2)
  4. Print the total number of the extracted person ids.(Use echo)
  5. Print the total number of the household ids having more than two extracted person ids. (Use echo)

For execution, bash person_female_30_50.sh test.txt person.txt

If Figure 1 is an input file, person.txt contains

405498152

405498152

405498151

The output will be 3 and 1.

3 indicates the number of the extracted person id.

1 indicates the number of the household id.

Submit your shell program — person_female_30_50.sh

———————————————————–

SPECIFICATION OF HW2

PYTHON PROGRAMMING

DESIGN A PYTHON PROGRAM RETURNING THE SAME RESULT AS HW1.

SUBMIT YOUR PYTHON PROGRAM (PERSON_FEMALE_30_50.PY)

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}