Fatima Jinnah Women University: Department of Computer Science
Fatima Jinnah Women University: Department of Computer Science
Fatima Jinnah Women University: Department of Computer Science
Assessment Brief
Subject Data Science
Assessment Assignment 1: Working with Dictionaries
Individual/Group Individual
Submission Date
Weighting 5%
Total Marks 20
Description
Task 1:
You will create a mini-database using dictionaries and functions. You will create a simple
nested dictionary that contains each person’s name, his/her phone no., gender, age and
category. The category depends upon age, which can be seen in the table below:
1 0 18 Child
2 18 35 Young
3 35 60 Adult
4 60 - Old
You will have to input all the relevant information i.e. name, age, gender and phone no,
from the user along with the total number of people to be included in the database. Also,
you will have to create one function for each entry input prompt(name, age, gender,
phone no), so that the called function inputs the name and return it to the main program.
This will be done for each person
Instructions:
In the first task of this assignment, you will create a database using dictionaries.
Each person's record should contain
Person’s name, his/her phone no., gender, age and category. The category should
be defined according to the table given in the Assignment handout.
When the program executes, it should first ask total number of people to be
included in the database.
Define 4 functions and you can name them like:
name_input()
phone_input()
gender_input()
age_input()
In the next step, the control should be transferred to each of these 4 functions,
each of which should ask user for specific information.
For example, the name_input() should ask: 'Please enter the name:' and then
returns the 'name' to the main program.
Similarly, gender_input should return the gender as Male/Female to the main
program.
Once all the input are taken, define another function: category() which returns the
category of the person based on the age. (Hint: use 'and' operation in defining
limits)
Once all the parameters of the database are collected, it should be stored in the
dictionary.
Since the code should support multiple person entry, you would use for loop to
execute all these functions every time.
Format Structure:
Task 2:
You will have to print all the information given in the database on the screen as well as
write this information in a text file named database.txt. So for a man named Alex in the
database, it should print and write, Alex’s phone no. is 123, Alex’s age in 36, Alex’s
category is Adult and so on. You are going to need d.item(), d.keys() and d.values()
functions as well as apply for-loop on it. Go through this link. (This contains all the
information needed)
https://www.programiz.com/python-programming/nested-dictionary
Instructions:
In the next task, you are going to do two things:
1) print all the entries of all the persons in the dictionary on the screen
(e.g. The age of David is 51)
(e.g. The Category of David is Adult)
Hint: recall that "%s"% or '{}.format' lesson from the lecture
2) Store all the information that is being printed on the screen in a text file named
'database.txt'. Following are some hints:
Print one line at a time and simultaneously store that line in the file.
Use d.items(), d.keys() and d.values() functions and run for-loops on them.
Also use d[key] combination.
Since it's a nested dictionary, you're going to need two for-loops.
The link given in the handout contains necessary information to get this thing
done.
Don't forget to close() the file at the end. Now open the text file and see if it
actually contains all the lines
printed on the screen.
'\n' operator is used to get the cursor to the next line.
Submission format
Submitted files should include Microsoft Word document containing cover page,
question statements, solution and snippets of your outputs.
Cover page should include following details:
Subject
Assignment
Name of Instructor
Name of Student
Roll No.
Note: Submission should be made through described channel by the Instructor such as
Google classroom.
Marking Rubrics
Criterion Excellent Adequate Substandard Not Even Close