Python

Class 12 CS project python

In these Python projects, you’ll dive into diverse applications ranging from managing student data, playing Tic Tac Toe, organizing contacts, to handling bank accounts and conducting quizzes. Each project offers valuable learning experiences and practical insights into Python programming and database management. Let’s explore and create!

Student Management System Project
Python Project using Pickle

Description: This Python project, driven by a menu, handles Student Management System data by pickling dictionary objects into a binary file. It enables the creation, reading, updating, and deletion of records in the binary file.

Program (student-management-system.py)

import pickle
import time
import os

def enter_student_details():
    print("Enter Student's Details")
    roll_number = int(input('Enter roll number: '))
    name = input('Enter name: ')
    english = int(input('Enter Marks in English: '))
    maths = int(input('Enter Marks in Maths: '))
    physics = int(input('Enter Marks in Physics: '))
    chemistry = int(input('Enter Marks in Chemistry: '))
    computer_science = int(input('Enter Marks in Computer Science: '))
    print()

    student = {
        'roll_number': roll_number,
        'name': name,
        'english': english,
        'maths': maths,
        'physics': physics,
        'chemistry': chemistry,
        'computer_science': computer_science
    }
    return student

def display_student_data(student):
    print('\nSTUDENT DETAILS..')
    print('Roll Number:', student['roll_number'])
    print('Name:', student['name'])
    print('English:', student['english'])
    print('Maths:', student['maths'])
    print('Physics:', student['physics'])
    print('Chemistry:', student['chemistry'])
    print('Computer Science:', student['computer_science'])

def display_student_data_tabular(student):
    print('{0:<8}{1:<20}{2:<10}{3:<10}{4:<10}{5:<10}{6:<10}'.format(
        student['roll_number'], student['name'], student['english'],
        student['maths'], student['physics'], student['chemistry'],
        student['computer_science']
    ))

def class_result():
    try:
        infile = open('student.dat', 'rb')
    except FileNotFoundError:
        print('No records found.')
        print('Go to the admin menu to create records.')
        return

    print('{0:<8}{1:<20}{2:<10}{3:<10}{4:<10}{5:<10}{6:<10}'.format(
        'Roll Number', 'Name', 'English', 'Maths', 'Physics', 'Chemistry', 'Computer Science'
    ))

    while True:
        try:
            student = pickle.load(infile)
            display_student_data_tabular(student)
        except EOFError:
            break

    infile.close()

def write_record():
    outfile = open('student.dat', 'ab')

    while True:
        pickle.dump(enter_student_details(), outfile)
        ans = input('Want to enter more records? (y/n): ')
        if ans.lower() == 'n':
            break

    outfile.close()

def read_records():
    try:
        infile = open('student.dat', 'rb')
    except FileNotFoundError:
        print('No records found.')
        return

    while True:
        try:
            student = pickle.load(infile)
            display_student_data(student)
        except EOFError:
            break

    infile.close()

def search_record():
    try:
        infile = open('student.dat', 'rb')
    except FileNotFoundError:
        print('No records found.')
        return

    found = False
    print('SEARCH RECORD')
    roll_number = int(input('Enter the roll number you want to search: '))

    while True:
        try:
            student = pickle.load(infile)
            if student['roll_number'] == roll_number:
                display_student_data(student)
                found = True
                break
        except EOFError:
            break

    if not found:
        print('Record not found.')

    infile.close()

def delete_record():
    print('DELETE RECORD')

    try:
        infile = open('student.dat', 'rb')
    except FileNotFoundError:
        print('No records found to delete.')
        return

    outfile = open("temp.dat", "wb")
    found = False

    roll_number = int(input('Enter roll number: '))
    while True:
        try:
            student = pickle.load(infile)
            if student['roll_number'] == roll_number:
                display_student_data(student)
                found = True
            else:
                pickle.dump(student, outfile)
        except EOFError:
            break

    if not found:
        print('Record not found.')
    else:
        print("Record found and deleted.")

    infile.close()
    outfile.close()
    os.remove("student.dat")
    os.rename("temp.dat", "student.dat")

def modify_record():
    print('\nMODIFY RECORD')

    try:
        infile = open('student.dat', 'rb')
    except FileNotFoundError:
        print('No records found to modify.')
        return

    found = False
    outfile = open("temp.dat", "wb")
    roll_number = int(input('Enter roll number: '))

    while True:
        try:
            student = pickle.load(infile)
            if student['roll_number'] == roll_number:
                print('Name:', student['name'])
                ans = input('Want to edit? (y/n): ')
                if ans.lower() == 'y':
                    student['name'] = input("Enter the name: ")

                print('English marks:', student['english'])
                ans = input('Want to edit? (y/n): ')
                if ans.lower() == 'y':
                    student['english'] = int(input("Enter new marks: "))

                print('Maths marks:', student['maths'])
                ans = input('Want to edit? (y/n): ')
                if ans.lower() == 'y':
                    student['maths'] = int(input("Enter new marks: "))

                print('Physics marks:', student['physics'])
                ans = input('Want to edit? (y/n): ')
                if ans.lower() == 'y':
                    student['physics'] = int(input("Enter new marks: "))

                print('Chemistry marks:', student['chemistry'])
                ans = input('Want to edit? (y/n): ')
                if ans.lower() == 'y':
                    student['chemistry'] = int(input("Enter new marks: "))

                print('Computer Science marks:', student['computer_science'])
                ans = input('Want to edit? (y/n): ')
                if ans.lower() == 'y':
                    student['computer_science'] = int(input("Enter new marks: "))

                pickle.dump(student, outfile)
                found = True
            else:
                pickle.dump(student, outfile)
        except EOFError:
            break

    if not found:
        print('Record not found.')
    else:
        print('Record updated.')
        display_student_data(student)

    infile.close()
    outfile.close()
    os.remove("student.dat")
    os.rename("temp.dat", "student.dat")

def introduction():
    print("=" * 80)
    print("{:^80s}".format("STUDENT"))
    print("{:^80s}".format("REPORT CARD"))
    print("{:^80s}".format("PROJECT"))
    print("{:^80s}".format("MADE BY: PyForSchool.com"))
    print("=" * 80)
    print()

def main_menu():
    time

.sleep(1)
    print("MAIN MENU")
    print("1. REPORT MENU")
    print("2. ADMIN MENU")
    print("3. EXIT")

def report_menu():
    time.sleep(1)
    print("REPORT MENU")
    print("1. CLASS RESULT")
    print("2. SEARCH STUDENT RECORD")
    print("3. BACK TO MAIN MENU")

def admin_menu():
    time.sleep(1)
    print("\nADMIN MENU")
    print("1. CREATE STUDENT RECORD")
    print("2. DISPLAY ALL STUDENTS RECORDS")
    print("3. SEARCH STUDENT RECORD ")
    print("4. MODIFY STUDENT RECORD ")
    print("5. DELETE STUDENT RECORD ")
    print("6. BACK TO MAIN MENU")

def main():
    introduction()
    while True:
        main_menu()
        choice = input('Enter choice (1-3): ')
        print()

        if choice == '1':
            while True:
                report_menu()
                rchoice = input('Enter choice (1-3): ')
                print()
                if rchoice == '1':
                    class_result()
                elif rchoice == '2':
                    search_record()
                elif rchoice == '3':
                    break
                else:
                    print('Invalid input!\n')
                print()
        elif choice == '2':
            while True:
                admin_menu()
                echoice = input('Enter choice (1-6): ')
                print()
                if echoice == '1':
                    write_record()
                elif echoice == '2':
                    read_records()
                elif echoice == '3':
                    search_record()
                elif echoice == '4':
                    modify_record()
                elif echoice == '5':
                    delete_record()
                elif echoice == '6':
                    break
                else:
                    print('Invalid input!\n')
        elif choice == '3':
            print('Thanks for using the Student Management System.')
            break
        else:
            print('Invalid input!')
            print()

# Call the main function.
main()

Join Our Whatsapp Group

Join Telegram group

Output

================================================================================
    STUDENT                                     
  REPORT CARD                                   
    PROJECT                                     
MADE BY: PyForSchool.com                            
================================================================================

MAIN MENU
1. REPORT MENU
2. ADMIN MENU
3. EXIT
Enter choice (1-3): 1

REPORT MENU
1. CLASS RESULT
2. SEARCH STUDENT RECORD
3. BACK TO MAIN MENU
Enter choice (1-3): 3

MAIN MENU
1. REPORT MENU
2. ADMIN MENU
3. EXIT
Enter choice (1-3): 2

ADMIN MENU
1. CREATE STUDENT RECORD
2. DISPLAY ALL STUDENTS RECORDS
3. SEARCH STUDENT RECORD 
4. MODIFY STUDENT RECORD 
5. DELETE STUDENT RECORD 
6. BACK TO MAIN MENU
Enter choice (1-6): 1

Enter Student's Details
Enter roll number: 110
Enter name: Nisha
Enter Marks in English: 90
Enter Marks in Maths: 87
Enter Marks in Physics: 85
Enter Marks in Chemistry: 78
Enter Marks in Computer Science: 92

Want to enter more records? (y/n): n


Tic Tac Toe Game Project
Python Project for Beginners

Description: This Python program is a text-based Tic Tac Toe game. It doesn’t have any graphics and can be played by two players. The game is played on a 3×3 grid, where players take turns marking squares with ‘X’ or ‘O’. The player who first forms a horizontal, vertical, or diagonal sequence of three marks wins. The program draws the game board, prompts users for their moves, switches players after each successful move, and displays the winner.

Tic Tac Toe Program

squares = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

def main():
    current_player = 1
    game_status = -1

    while game_status == -1:
        display_board()

        if current_player % 2 == 1:
            current_player = 1
        else:
            current_player = 2

        print('\nPlayer', current_player)
        choice = int(input('Enter a number:'))

        if current_player == 1:
            mark = 'X'
        else:
            mark = 'O'

        if 1 <= choice <= 9 and squares[choice] == choice:
            squares[choice] = mark
        else:
            print('Invalid move ')
            current_player -= 1

        game_status = check_game_status()
        current_player += 1

    print('RESULT')    
    if game_status == 1:
        print('Player', current_player - 1,'wins')
    else:
        print('Game draw')

def check_game_status():
    if squares[1] == squares[2] == squares[3] or \
       squares[4] == squares[5] == squares[6] or \
       squares[7] == squares[8] == squares[9] or \
       squares[1] == squares[4] == squares[7] or \
       squares[2] == squares[5] == squares[8] or \
       squares[3] == squares[6] == squares[9] or \
       squares[1] == squares[5] == squares[9] or \
       squares[3] == squares[5] == squares[7]:
        return 1
    elif all(square != num for num in range(1, 10) for square in squares):
        return 0
    else:
        return -1

def display_board():
    print('\n\n\tTic Tac Toe\n\n')
    print('Player 1 (X)  -  Player 2 (O)' ) 
    print()
    print('     |     |     ' )
    print(' ' , squares[1] ,' | ' , squares[2] ,' |  ' , squares[3] )
    print('_____|_____|_____' )
    print('     |     |     ' )
    print(' ' , squares[4] ,' | ' , squares[5] ,' |  ' , squares[6] )
    print('_____|_____|_____' )
    print('     |     |     ' )
    print(' ' , squares[7] ,' | ' , squares[8] ,' |  ' , squares[9] )
    print('     |     |     ' )

main()

Contact Book – Python Project Using MySQL

Project Overview:
A contact book is a tool for storing contact details such as name, address, phone number, and email address. In this project, you’ll build a Contact Book application that allows users to:

  1. Add new contact records.
  2. Search for contacts by name.
  3. Display all contact records.
  4. Delete contact records.
  5. Modify contact records.

Prerequisites:
Before you begin, ensure you have the following installed:

Join Our Whatsapp Group

Join Telegram group

Setting Up the Database:
To start, create a MySQL database to store contact information. Here are the steps:

  1. Open your MySQL command-line client.
  2. Execute the following SQL commands to create a database named “contact”:
   CREATE DATABASE IF NOT EXISTS contact;

Building the Application:

We’re providing a simplified version of the contact book. You can enhance and customize it as you learn more.

import mysql.connector
import time

# Connect to MySQL database
db = mysql.connector.connect(
    host="localhost",
    user="root",
    password="1234",
    database="contact"
)

cursor = db.cursor()

# Create table if not exists
cursor.execute("""
    CREATE TABLE IF NOT EXISTS book (
        name char(30) primary key,
        address char(100),
        mobile char(15),
        email char(30)
    );
""")

def intro():
    print("=" * 80)
    print("{:^80s}".format("CONTACT"))
    print("{:^80s}".format("BOOK"))
    print("{:^80s}".format("PROJECT"))
    print("{:^80s}".format("MADE BY: PyForSchool.com"))
    print("=" * 80)
    print()
    time.sleep(2)

def create_record():
    name = input("Enter name: ")
    address = input("Enter address: ")
    mobile = input("Enter mobile: ")
    email = input("Enter email: ")
    sql = "INSERT INTO book(name,address,mobile,email) VALUES (%s,%s,%s,%s)"
    record = (name, address, mobile, email)
    cursor.execute(sql, record)
    db.commit()
    print("Record Entered Successfully\n")

def search(name):
    sql = "SELECT * FROM book WHERE name = %s"
    value = (name,)
    cursor.execute(sql, value)
    record = cursor.fetchone()
    if record is None:
        print("No such record exists")
    else:
        print('Name:', record[0])
        print('Address:', record[1])
        print('Mobile:', record[2])
        print('E-mail:', record[3])

def display_all():
    cursor.execute("SELECT * FROM book")
    print('{0:20}{1:30}{2:15}{3:30}'.format('NAME', 'ADDRESS', 'MOBILE NO', 'E-MAIL'))
    for record in cursor:
        print('{0:20}{1:30}{2:15}{3:30}'.format(record[0], record[1], record[2], record[3]))

def delete_record(name):
    sql = "DELETE FROM book WHERE name = %s"
    value = (name,)
    cursor.execute(sql, value)
    db.commit()
    if cursor.rowcount == 0:
        print("Record not found")
    else:
        print("Record deleted successfully")

def modify_record(name):
    sql = "SELECT * FROM book WHERE name = %s"
    value = (name,)
    cursor.execute(sql, value)
    record = cursor.fetchone()
    if record is None:
        print("No such record exists")
    else:
        while True:
            print("\nPress the option you want to edit: ")
            print("1. Name")
            print("2. Address")
            print("3. Mobile")
            print("4. BACK")
            print()
            ch = int(input("Select Your Option (1-4): "))
            if ch == 1:
                new_name = input("Enter new name: ")
                sql = "UPDATE book SET name = %s WHERE name = %s"
                values = (new_name, name)
                cursor.execute(sql, values)
                db.commit()
                print(cursor.rowcount, "record updated successfully")
            elif ch == 2:
                new_address = input("Enter new address: ")
                sql = "UPDATE book SET address = %s WHERE name = %s"
                values = (new_address, name)
                cursor.execute(sql, values)
                db.commit()
                print(cursor.rowcount, "record updated successfully")
            elif ch == 3:
                new_mobile = input("Enter new mobile : ")
                sql = "UPDATE book SET mobile = %s WHERE name = %s"
                values = (new_mobile, name)
                cursor.execute(sql, values)
                db.commit()
                print(cursor.rowcount, "record updated successfully")
            elif ch == 4:
                break
            else:
                print("Invalid choice !!!\n")

def main():
    intro()
    while True:
        print("\nMAIN MENU ")
        print("1. ADD NEW RECORD")
        print("2. SEARCH RECORD")
        print("3. DISPLAY ALL RECORDS")
        print("4. DELETE RECORD")
        print("5. MODIFY RECORD")
        print("6. EXIT")
        print()
        ch = int(input("Select Your Option (1-6): "))
        print()
        if ch == 1:
            print("ADD NEW RECORD")
            create_record()
        elif ch == 2:
            print("SEARCH RECORD BY NAME")
            name = input("Enter name: ")
            search(name)
        elif ch == 3:
            print("DISPLAY ALL RECORDS")
            display_all()
        elif ch == 4:
            print("DELETE RECORD")
            name = input("Enter name: ")
            delete_record(name)
        elif ch == 5:
            print("MODIFY RECORD")
            name = input("Enter name: ")
            modify_record(name)
        elif ch == 6:
            print("Thanks for using Contact Book")
            db.close()
            break
        else:
            print("Invalid choice")

main()

Output

Learning and Customization: This Contact Book project offers an excellent opportunity to learn and practice Python and database management. As you become more proficient, consider expanding the project by adding features like user authentication and more advanced search and filter options.

Bank Management System

Project Idea for Class 12

The Bank Management System is a Python-based application designed to manage bank accounts and related operations efficiently. It provides a user-friendly interface for both customers and administrators to interact with the bank’s database securely. The system utilizes MySQL for secure storage and retrieval of account information.

Project Description

The Bank Management System is a comprehensive solution for managing bank accounts and related operations. Here’s a breakdown of its key features:

User Authentication:

  • Users must log in with their account number and password.
  • Passwords are securely stored using hashing techniques.

Customer Operations:

  • Customers can check their account balance.
  • Deposit and withdraw funds from their accounts.
  • Transfer funds to other accounts within the bank.
  • Change their account passwords for security.

Admin Operations:

  • Administrators can log in with a special password.
  • Create new customer accounts.
  • Update customer account details.
  • Delete customer accounts.
  • Search for customer accounts by account number or name.
  • View a list of all customer accounts.

How To Code The Project:

  1. Divide your code into smaller functions, each with a specific purpose.
  2. Start with basic functionalities and gradually add more features.
  3. Seek help from instructors, classmates, or online communities if needed.

Join Our Whatsapp Group

Join Telegram group

Prerequisites:

Before you begin, ensure you have the following installed:

This project provides an excellent opportunity to enhance your Python skills while building a practical application for managing bank accounts. Don’t hesitate to seek assistance and explore online resources for guidance. Good luck with your project!

Multiple Choice Quiz Project

Python Project for Class 12

The Quiz Master Application allows users to participate in quizzes and administrators to manage quiz questions. Users can test their understanding of various topics by answering multiple-choice questions, while administrators can create, edit, and delete quiz questions to keep the content dynamic.

Project Description

The Quiz Master is a Python-based application that serves as an interactive quiz management system. It establishes a connection to a local MySQL database, ‘quiz’, and creates tables for storing questions and high scores. The program offers features for users to take quizzes, view scores, and compete for high scores, while administrators can manage quiz questions through an admin panel.

Key Features of Quiz Master

Quiz Module:

  • Users can start a quiz by choosing the “Start Quiz” option from the main menu.
  • The quiz module fetches up to 10 random questions from the MySQL database.
  • Users are presented with multiple-choice questions and must select the correct answer.
  • The user’s score is calculated based on the number of correct answers.
  • At the end of the quiz, the user’s score is displayed.

High Scores:

  • Users can view the top 10 high scores by choosing the “High Scores” option from the main menu.
  • High scores are retrieved from the MySQL database and displayed, including the player’s name, score, and timestamp.

Admin Panel:

  • Authorized users can access an admin panel by providing a username and password.
  • Admins can add new multiple-choice questions to the quiz database.
  • Edit existing questions, including options and correct answers.
  • Delete questions from the quiz database.
  • View all questions currently in the database.

How To Code The Project

  1. Divide your code into smaller functions: Each function should have a specific purpose and responsibility.
  2. Begin with basic functionalities: Start with features like user authentication, quiz module, and high scores.
  3. Gradually add more features: Once the basic functionalities are working, add admin panel features.
  4. Seek help if needed: Don’t hesitate to ask for help or guidance from instructors, classmates, or online communities.

Prerequisites

Before starting the project, ensure you have the following installed:

This project offers an excellent opportunity to enhance your Python skills while building a practical application for managing quizzes. Good luck with your project!

Frequently Asked Questions

Student Management System Project

Q: What is the purpose of the Student Management System project?

A: The Student Management System project aims to manage student data by pickling dictionary objects into a binary file. It enables the creation, reading, updating, and deletion of student records in the binary file.

Q: What functionalities does the Student Management System project offer?

A: The project allows users to enter student details, display student data, view class results, write student records, read student records, search for student records, delete student records, and modify student records.

Tic Tac Toe Game Project

Q: What is the Tic Tac Toe Game project about?

A: The Tic Tac Toe Game project is a text-based game where two players take turns marking squares in a 3×3 grid with ‘X’ or ‘O’. The player who first forms a horizontal, vertical, or diagonal sequence of three marks wins.

Q: How does the Tic Tac Toe Game project work?

A: Players input their moves by selecting numbers corresponding to squares on the game board. The program switches players after each move, checks for winning conditions, and declares the winner or a draw.

Contact Book – Python Project Using MySQL

Q: What is the Contact Book project about?

A: The Contact Book project is designed to store and manage contact details such as name, address, phone number, and email address using a MySQL database. It allows users to add, search, display, delete, and modify contact records.

Q: What are the key features of the Contact Book project?

A: The project offers functionalities for creating new contact records, searching for contacts by name, displaying all contact records, deleting contact records, and modifying contact records.

Bank Management System Project

Q: What is the Bank Management System project for Class 12?

A: The Bank Management System project is a Python-based application designed to manage bank accounts and related operations efficiently. It provides a user-friendly interface for both customers and administrators to interact with the bank’s database securely.

Q: What functionalities does the Bank Management System project offer?

A: The project includes user authentication, customer operations such as checking balance, depositing, withdrawing, transferring funds, changing passwords, and admin operations such as creating, updating, deleting customer accounts, searching, and viewing all customer accounts.

Multiple Choice Quiz Project

Q: What is the Multiple Choice Quiz project for Class 12?

A: The Multiple Choice Quiz project is an interactive quiz management system. It allows users to participate in quizzes and administrators to manage quiz questions. Users can test their understanding of various topics by answering multiple-choice questions.

Q: What are the key features of the Multiple Choice Quiz project?

A: The project includes a quiz module for users to start quizzes, fetch random questions, select answers, calculate scores, and view scores. It also offers high scores display and an admin panel for managing quiz questions.

Nilesh Payghan

Share
Published by
Nilesh Payghan

Recent Posts

Auth0 vs Firebase

When choosing an authentication service for your application, two popular options are Auth0 and Firebase.…

4 days ago

Celebrating Family Connections: Flutterwave’s Insights and Innovations on International Day of Family Remittances (IDFR) 2024

In honor of the International Day of Family Remittances (IDFR) 2024, Flutterwave, Africa's leading payment…

2 weeks ago

PadhAI App Smashes UPSC Exam with 170 out of 200 in Under 7 Minutes!

PadhAI, a groundbreaking AI app, has stunned the education world by scoring 170 out of…

2 weeks ago

Free Vector Database

Vector databases are essential for managing high-dimensional data efficiently, making them crucial in fields like…

3 weeks ago

Flutter App Development Services: A Hilarious Journey Through the World of Flutter

Welcome to the whimsical world of Flutter app development services! From crafting sleek, cross-platform applications…

3 weeks ago

Flutter App Development

Flutter, Google's UI toolkit, has revolutionized app development by enabling developers to build natively compiled…

3 weeks ago