Code Monkey home page Code Monkey logo

student-record-store's Introduction

Python program to sort and fond the data in student records.

Difficulty Lavel: Medium

Consider a software for maintaining records of the students in a class. Consider the following functions which are required to be performed:

  • Sorting of names according to First Name of the students.
  • Finding the Minimum marks among all the marks
  • Finding contact number of student using his/her First Name.

Approach: For the above problem we should use a dictionary that either takes a name as a whole to key and other data as value to it or vice versa. Here I have taken the name as a key and contact number, marks as the value associated with the name. So at first the user needs to enter the details of the students and these details will be stored in dictionary as {[‘first name’, ‘second name’]:(‘contact number’, ‘marks’)}. Then we create a new list of tuples that store data according to the function requirement. In the program four user-defined functions have been created:

  1. sort( ) function that sorts the record based on the first name.
  2. minmarks( ) function that finds the minimum marks from all records.
  3. searchdetail( ) function that takes first name as an input and fetch student contact number from the corresponding record.
  4. option() function for showing the options.

Prerequisites

Python 3

How to run the script

Execute

python StudentInfo.py

print("*********Program for Student Information*********")

D = dict()

n = int(input('How many student record you want to store?? '))

# Add student information
# to the dictionary
for i in range(0, n):
    x, y = input(
        "Enter the complete name (First and last name) of student: ").split()
    z = input("Enter contact number: ")
    m = input('Enter Marks: ')
    D[x, y] = (z, m)

# define a function for shorting
# names based on first name


def sort():
    ls = list()
    # fetch key and value using
    # items() method
    for sname, details in D.items():

        # store key parts as an tuple
        tup = (sname[0], sname[1])

        # add tuple to the list
        ls.append(tup)

    # sort the final list of tuples
    ls = sorted(ls)
    for i in ls:

        # print first name and second name
        print(i[0], i[1])
    return

# define a function for
# finding the minimum marks
# in stored data


def minmarks():
    ls = list()
    # fetch key and value using
    # items() methods
    for sname, details in D.items():
        # add details second element
        # (marks) to the list
        ls.append(details[1])

    # sort the list elemnts
    ls = sorted(ls)
    print("Minimum marks: ", min(ls))

    return

# define a function for searching
# student contact number


def searchdetail(fname):
    ls = list()

    for sname, details in D.items():

        tup = (sname, details)
        ls.append(tup)

    for i in ls:
        if i[0][0] == fname:
            print(i[1][0])
    return

# define a funtion for
# asking the options


def option():

    choice = int(input('Enter the operation detail: \n \
    1: Sorting using first name \n \
    2: Finding Minimum marks \n \
    3: Search contact number using first name: \n \
    4: Exit\n \
    Option: '))

    if choice == 1:
        # finction call
        sort()
        print('Want to perform some other operation??? Y or N: ')
        inp = input()
        if inp == 'Y':
            option()

        # exit finction call
        exit()

    elif choice == 2:
        minmarks()
        print('Want to perform some other operation??? Y or N: ')

        inp = input()
        if inp == 'Y':
            option()
        exit()

    elif choice == 3:
        first = input('Enter first name of student: ')
        searchdetail(first)

        print('Want to perform some other operation??? Y or N: ')
        inp = input()
        if inp == 'Y':
            option()

        exit()
    else:
        print('Thanks for executing me!!!!')
        exit()


option()

Author Name

Vikrant

student-record-store's People

Contributors

thevkrant avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.