Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
369 changes: 369 additions & 0 deletions Basic_python__projects_(1).ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,369 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/Chinmay-Nishank/Assuming-your-branch-name-is-my-future-branch/blob/main/Basic_python__projects_(1).ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"background_save": true,
"base_uri": "https://localhost:8080/"
},
"id": "HJ_tWUd6XhSq",
"outputId": "b1a44a99-f0c0-4ab8-ffcf-3caa919ccc87"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"1.Add 2.View 3.Issue 4.Return 5.Exit\n",
"\n",
"1.Add 2.View 3.Issue 4.Return 5.Exit\n",
"\n",
"1.Add 2.View 3.Issue 4.Return 5.Exit\n",
"Choice: 1\n"
]
}
],
"source": [
"class Library:\n",
" def __init__(self):\n",
" self.books = {}\n",
"\n",
" def add(self, name, qty):\n",
" self.books[name] = self.books.get(name, 0) + qty\n",
"\n",
" def view(self):\n",
" if not self.books:\n",
" print(\"No books available\")\n",
" else:\n",
" for b, q in self.books.items():\n",
" print(b, \"-\", q)\n",
"\n",
" def issue(self, name):\n",
" if self.books.get(name, 0) > 0:\n",
" self.books[name] -= 1\n",
" print(\"Book issued\")\n",
" else:\n",
" print(\"Not available\")\n",
"\n",
" def return_book(self, name):\n",
" self.books[name] = self.books.get(name, 0) + 1\n",
" print(\"Book returned\")\n",
"\n",
"\n",
"lib = Library()\n",
"\n",
"while True:\n",
" print(\"\\n1.Add 2.View 3.Issue 4.Return 5.Exit\")\n",
" ch = input(\"Choice: \")\n",
"\n",
" if ch == \"1\":\n",
" lib.add(input(\"Book name: \"), int(input(\"Qty: \")))\n",
" elif ch == \"2\":\n",
" lib.view()\n",
" elif ch == \"3\":\n",
" lib.issue(input(\"Book name: \"))\n",
" elif ch == \"4\":\n",
" lib.return_book(input(\"Book name: \"))\n",
" elif ch == \"5\":\n",
" break\n",
" else:\n",
" print(\"Invalid choice\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "Y2W--o8AY6k4"
},
"outputs": [],
"source": [
"import time\n",
"\n",
"while True:\n",
" print(\" Red Light - STOP\")\n",
" time.sleep(3)\n",
"\n",
" print(\"Yellow Light - WAIT\")\n",
" time.sleep(2)\n",
"\n",
" print(\"Green Light - GO\")\n",
" time.sleep(3)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "tQtnWVEOZVvy"
},
"outputs": [],
"source": [
"class Cart:\n",
" def __init__(self):\n",
" self.items = {}\n",
"\n",
" def add(self, name, price, qty):\n",
" self.items[name] = [price, qty]\n",
"\n",
" def remove(self, name):\n",
" if name in self.items:\n",
" del self.items[name]\n",
" print(\"Item removed\")\n",
" else:\n",
" print(\"Item not found\")\n",
"\n",
" def view(self):\n",
" total = 0\n",
" if not self.items:\n",
" print(\"Cart is empty\")\n",
" else:\n",
" for name, (price, qty) in self.items.items():\n",
" cost = price * qty\n",
" total += cost\n",
" print(name, \"-\", qty, \"x\", price, \"=\", cost)\n",
" print(\"Total:\", total)\n",
"\n",
"\n",
"cart = Cart()\n",
"\n",
"while True:\n",
" print(\"\\n1.Add 2.Remove 3.View 4.Exit\")\n",
" ch = input(\"Choice: \")\n",
"\n",
" if ch == \"1\":\n",
" name = input(\"Product name: \")\n",
" price = float(input(\"Price: \"))\n",
" qty = int(input(\"Quantity: \"))\n",
" cart.add(name, price, qty)\n",
"\n",
" elif ch == \"2\":\n",
" cart.remove(input(\"Product name: \"))\n",
"\n",
" elif ch == \"3\":\n",
" cart.view()\n",
"\n",
" elif ch == \"4\":\n",
" break\n",
"\n",
" else:\n",
" print(\"Invalid choice\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "X1_TdeRrZzVZ"
},
"outputs": [],
"source": [
"class ATM:\n",
" def __init__(self):\n",
" self.accounts = {\n",
" \"1001\": {\"pin\": \"1234\", \"balance\": 5000},\n",
" \"1002\": {\"pin\": \"5678\", \"balance\": 8000}\n",
" }\n",
"\n",
" def login(self, acc, pin):\n",
" if acc in self.accounts and self.accounts[acc][\"pin\"] == pin:\n",
" return True\n",
" return False\n",
"\n",
" def check_balance(self, acc):\n",
" print(\"Balance:\", self.accounts[acc][\"balance\"])\n",
"\n",
" def deposit(self, acc, amt):\n",
" self.accounts[acc][\"balance\"] += amt\n",
" print(\"Deposited Successfully\")\n",
"\n",
" def withdraw(self, acc, amt):\n",
" if self.accounts[acc][\"balance\"] >= amt:\n",
" self.accounts[acc][\"balance\"] -= amt\n",
" print(\"Withdraw Successful\")\n",
" else:\n",
" print(\"Insufficient Balance\")\n",
"\n",
"\n",
"atm = ATM()\n",
"\n",
"acc = input(\"Enter Account Number: \")\n",
"pin = input(\"Enter PIN: \")\n",
"\n",
"if atm.login(acc, pin):\n",
" while True:\n",
" print(\"\\n1.Balance 2.Deposit 3.Withdraw 4.Exit\")\n",
" ch = input(\"Choice: \")\n",
"\n",
" if ch == \"1\":\n",
" atm.check_balance(acc)\n",
" elif ch == \"2\":\n",
" atm.deposit(acc, float(input(\"Amount: \")))\n",
" elif ch == \"3\":\n",
" atm.withdraw(acc, float(input(\"Amount: \")))\n",
" elif ch == \"4\":\n",
" break\n",
" else:\n",
" print(\"Invalid choice\")\n",
"else:\n",
" print(\"Invalid Account or PIN\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "CwhZZjCwaa4V"
},
"outputs": [],
"source": [
"class GradeBook:\n",
" def __init__(self):\n",
" self.students = {}\n",
"\n",
" def add_student(self, name, marks):\n",
" self.students[name] = marks\n",
"\n",
" def view_students(self):\n",
" if not self.students:\n",
" print(\"No records found\")\n",
" else:\n",
" for name, marks in self.students.items():\n",
" avg = sum(marks) / len(marks)\n",
" print(name, \"Marks:\", marks, \"Average:\", round(avg, 2))\n",
"\n",
" def calculate_grade(self, avg):\n",
" if avg >= 90:\n",
" return \"A\"\n",
" elif avg >= 75:\n",
" return \"B\"\n",
" elif avg >= 60:\n",
" return \"C\"\n",
" elif avg >= 40:\n",
" return \"D\"\n",
" else:\n",
" return \"F\"\n",
"\n",
"\n",
"gb = GradeBook()\n",
"\n",
"while True:\n",
" print(\"\\n1.Add Student 2.View Records 3.Exit\")\n",
" ch = input(\"Choice: \")\n",
"\n",
" if ch == \"1\":\n",
" name = input(\"Student Name: \")\n",
" marks = list(map(int, input(\"Enter marks separated by space: \").split()))\n",
" gb.add_student(name, marks)\n",
"\n",
" elif ch == \"2\":\n",
" if not gb.students:\n",
" print(\"No records found\")\n",
" else:\n",
" for name, marks in gb.students.items():\n",
" avg = sum(marks) / len(marks)\n",
" grade = gb.calculate_grade(avg)\n",
" print(name, \"Average:\", round(avg, 2), \"Grade:\", grade)\n",
"\n",
" elif ch == \"3\":\n",
" break\n",
" else:\n",
" print(\"Invalid choice\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "BCm0dM55abjP"
},
"outputs": [],
"source": [
"import hashlib\n",
"\n",
"class PasswordManager:\n",
" def __init__(self):\n",
" self.users = {}\n",
"\n",
" def hash_password(self, password):\n",
" return hashlib.sha256(password.encode()).hexdigest()\n",
"\n",
" def register(self, username, password):\n",
" if username in self.users:\n",
" print(\"User already exists\")\n",
" else:\n",
" self.users[username] = self.hash_password(password)\n",
" print(\"User registered successfully\")\n",
"\n",
" def login(self, username, password):\n",
" if username in self.users:\n",
" if self.users[username] == self.hash_password(password):\n",
" print(\"Login successful\")\n",
" else:\n",
" print(\"Incorrect password\")\n",
" else:\n",
" print(\"User not found\")\n",
"\n",
"\n",
"pm = PasswordManager()\n",
"\n",
"while True:\n",
" print(\"\\n1.Register 2.Login 3.Exit\")\n",
" ch = input(\"Choice: \")\n",
"\n",
" if ch == \"1\":\n",
" u = input(\"Username: \")\n",
" p = input(\"Password: \")\n",
" pm.register(u, p)\n",
"\n",
" elif ch == \"2\":\n",
" u = input(\"Username: \")\n",
" p = input(\"Password: \")\n",
" pm.login(u, p)\n",
"\n",
" elif ch == \"3\":\n",
" break\n",
"\n",
" else:\n",
" print(\"Invalid choice\")"
]
},
{
"cell_type": "code",
"source": [],
"metadata": {
"id": "Rj16nnHnWV7J"
},
"execution_count": null,
"outputs": []
}
],
"metadata": {
"colab": {
"provenance": [],
"include_colab_link": true
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Loading