diff --git a/Basic_python__projects_(1).ipynb b/Basic_python__projects_(1).ipynb new file mode 100644 index 0000000..5ad914a --- /dev/null +++ b/Basic_python__projects_(1).ipynb @@ -0,0 +1,369 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "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 +} \ No newline at end of file diff --git a/Exception_handling_problems b/Exception_handling_problems new file mode 100644 index 0000000..7781354 --- /dev/null +++ b/Exception_handling_problems @@ -0,0 +1,284 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [], + "authorship_tag": "ABX9TyNq2kW8yHS4UXPL+rHUfX+k", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "EScIumbUpxuT" + }, + "outputs": [], + "source": [ + "# Student Grade management System :\n", + "class InvalidStudentID(Exception):\n", + " pass\n", + "\n", + "students = {}\n", + "\n", + "while True:\n", + " try:\n", + " choice = input(\"1.Add 2.Update 3.Delete 4.View 5.Exit : \")\n", + "\n", + " if choice == \"1\":\n", + " sid = input(\"Enter student ID: \")\n", + " if sid == \"\":\n", + " raise InvalidStudentID(\"Student ID cannot be empty\")\n", + "\n", + " grade = int(input(\"Enter grade: \"))\n", + " students[sid] = grade\n", + " print(\"Student added\")\n", + "\n", + " elif choice == \"2\":\n", + " sid = input(\"Enter student ID to update: \")\n", + " if sid not in students:\n", + " raise InvalidStudentID(\"Student ID not found\")\n", + "\n", + " grade = int(input(\"Enter new grade: \"))\n", + " students[sid] = grade\n", + " print(\"Grade updated\")\n", + "\n", + " elif choice == \"3\":\n", + " sid = input(\"Enter student ID to delete: \")\n", + " if sid not in students:\n", + " raise InvalidStudentID(\"Student ID not found\")\n", + "\n", + " del students[sid]\n", + " print(\"Student deleted\")\n", + "\n", + " elif choice == \"4\":\n", + " print(students)\n", + "\n", + " elif choice == \"5\":\n", + " break\n", + "\n", + " except ValueError:\n", + " print(\"Grade must be a number\")\n", + "\n", + " except InvalidStudentID as e:\n", + " print(e)" + ] + }, + { + "cell_type": "code", + "source": [ + "# Contact Book :\n", + "contacts = {}\n", + "\n", + "try:\n", + " name = input(\"Enter name: \")\n", + " phone = input(\"Enter phone number: \")\n", + "\n", + " if name == \"\" or phone == \"\":\n", + " raise Exception(\"Fields cannot be empty\")\n", + "\n", + " if not phone.isdigit():\n", + " raise Exception(\"Invalid phone number\")\n", + "\n", + " if name in contacts:\n", + " raise Exception(\"Duplicate contact\")\n", + "\n", + " contacts[name] = phone\n", + "\n", + " search = input(\"Search contact name: \")\n", + "\n", + " print(\"Phone:\", contacts[search])\n", + "\n", + "except KeyError:\n", + " print(\"Contact not found\")\n", + "\n", + "except Exception as e:\n", + " print(e)" + ], + "metadata": { + "id": "ahv22cQTqGpo" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "# Banking System With Transactions :\n", + "class OverdraftError(Exception):\n", + " pass\n", + "\n", + "accounts = {\"A101\": 5000, \"A102\": 3000}\n", + "\n", + "try:\n", + " sender = input(\"Sender account: \")\n", + " receiver = input(\"Receiver account: \")\n", + " amount = int(input(\"Enter amount: \"))\n", + "\n", + " if sender not in accounts or receiver not in accounts:\n", + " raise Exception(\"Invalid account number\")\n", + "\n", + " if accounts[sender] < amount:\n", + " raise OverdraftError(\"Insufficient balance\")\n", + "\n", + " accounts[sender] -= amount\n", + " accounts[receiver] += amount\n", + "\n", + " print(\"Transaction successful\")\n", + "\n", + "except OverdraftError as e:\n", + " print(e)\n", + "\n", + "except ValueError:\n", + " print(\"Invalid amount\")\n", + "\n", + "except Exception as e:\n", + " print(e)" + ], + "metadata": { + "id": "9pntvCh3qZjL" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "# E-comerce order management :\n", + "stock = {\"Laptop\": 5, \"Phone\": 10}\n", + "\n", + "try:\n", + " product = input(\"Enter product: \")\n", + " quantity = int(input(\"Enter quantity: \"))\n", + " coupon = input(\"Enter coupon code: \")\n", + "\n", + " if product not in stock:\n", + " raise Exception(\"Product not available\")\n", + "\n", + " if stock[product] < quantity:\n", + " raise Exception(\"Out of stock\")\n", + "\n", + " if coupon != \"SAVE10\":\n", + " raise Exception(\"Invalid coupon code\")\n", + "\n", + " payment = input(\"Payment method: \")\n", + "\n", + " if payment not in [\"UPI\", \"Card\", \"Cash\"]:\n", + " raise Exception(\"Invalid payment method\")\n", + "\n", + " stock[product] -= quantity\n", + " print(\"Order placed successfully\")\n", + "\n", + "except ValueError:\n", + " print(\"Invalid quantity\")\n", + "\n", + "except Exception as e:\n", + " print(e)" + ], + "metadata": { + "id": "E7JTOPPtqzXT" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "# Custom Exception Framework (Inventory System)\n", + "class OutOfStockError(Exception):\n", + " pass\n", + "\n", + "class InvalidProductIDError(Exception):\n", + " pass\n", + "\n", + "inventory = {\"P101\": 10, \"P102\": 0}\n", + "\n", + "try:\n", + " pid = input(\"Enter product ID: \")\n", + " qty = int(input(\"Enter quantity: \"))\n", + "\n", + " if pid not in inventory:\n", + " raise InvalidProductIDError(\"Invalid Product ID\")\n", + "\n", + " if inventory[pid] == 0:\n", + " raise OutOfStockError(\"Product out of stock\")\n", + "\n", + " inventory[pid] -= qty\n", + " print(\"Product purchased\")\n", + "\n", + "except InvalidProductIDError as e:\n", + " print(e)\n", + "\n", + "except OutOfStockError as e:\n", + " print(e)" + ], + "metadata": { + "id": "dYHg2ovlrGJS" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "# Flight Booking System\n", + "class SeatNotAvailable(Exception):\n", + " pass\n", + "\n", + "seats = 5\n", + "\n", + "try:\n", + " name = input(\"Passenger name: \")\n", + " seats_required = int(input(\"Seats required: \"))\n", + "\n", + " if name == \"\":\n", + " raise Exception(\"Invalid passenger details\")\n", + "\n", + " if seats_required > seats:\n", + " raise SeatNotAvailable(\"Seats not available\")\n", + "\n", + " payment = input(\"Payment status (success/fail): \")\n", + "\n", + " if payment == \"fail\":\n", + " raise Exception(\"Payment failed\")\n", + "\n", + " seats -= seats_required\n", + "\n", + " print(\"Flight booked successfully\")\n", + "\n", + "except SeatNotAvailable as e:\n", + " print(e)\n", + "\n", + "except ValueError:\n", + " print(\"Invalid seat number\")\n", + "\n", + "except Exception as e:\n", + " print(e)" + ], + "metadata": { + "id": "fpbaFgaUrRU1" + }, + "execution_count": null, + "outputs": [] + } + ] +} \ No newline at end of file diff --git a/README.md b/README.md index 7accd68..762e494 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ git switch ### Step 2: Make changes You can add a new file, edit an existing file, or delete a file. -To keep things simple, let's edit the `index.html` file by changing the name to "GitGoing" on line 10. +To keep things simple, let's edit the `index.html` file by changing the name to "GitGoing-YourLastName" on line 10. ### Step 3: Stage your changes diff --git a/index.html b/index.html index b185ab1..3d15e5f 100644 --- a/index.html +++ b/index.html @@ -7,12 +7,10 @@
-

Todo List

+

Git Going

- - - \ No newline at end of file + \ No newline at end of file diff --git a/styles.css b/style.css similarity index 100% rename from styles.css rename to style.css diff --git a/tnp1.ipynb b/tnp1.ipynb new file mode 100644 index 0000000..235a1bd --- /dev/null +++ b/tnp1.ipynb @@ -0,0 +1,424 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [], + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "-U5e8pd8J8Ks", + "outputId": "fa2f3353-e2de-4d50-d5ce-fea57642353e" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Enter first number: 2\n", + "Enter second number: 1\n", + "Sum: 3\n", + "Difference: 1\n", + "Product: 2\n", + "Division: 2.0\n", + "Even/Odd: Even\n", + "Float value: 2.0\n" + ] + } + ], + "source": [ + "a = int(input(\"Enter first number: \"))\n", + "b = int(input(\"Enter second number: \"))\n", + "\n", + "print(\"Sum:\", a + b)\n", + "print(\"Difference:\", a - b)\n", + "print(\"Product:\", a * b)\n", + "print(\"Division:\", a / b)\n", + "\n", + "print(\"Even/Odd:\", \"Even\" if a % 2 == 0 else \"Odd\")\n", + "\n", + "print(\"Float value:\", float(a))" + ] + }, + { + "cell_type": "code", + "source": [ + "s = input(\"Enter sentence: \")\n", + "\n", + "vowels = \"aeiouAEIOU\"\n", + "v = sum(1 for ch in s if ch in vowels)\n", + "c = sum(1 for ch in s if ch.isalpha() and ch not in vowels)\n", + "\n", + "print(\"Vowels:\", v)\n", + "print(\"Consonants:\", c)\n", + "print(\"Reverse:\", s[::-1])\n", + "print(\"Underscore:\", s.replace(\" \", \"_\"))\n", + "print(\"Capitalized:\", s.title())" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "-VPaZQJhMFBf", + "outputId": "5fdd7f08-cb09-4605-85d2-e326b9279efd" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Enter sentence: Swaraj\n", + "Vowels: 2\n", + "Consonants: 4\n", + "Reverse: jarawS\n", + "Underscore: Swaraj\n", + "Capitalized: Swaraj\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "t = (1, \"a\", 5, 10.5, 3)\n", + "\n", + "nums = [x for x in t if type(x) in [int, float]]\n", + "print(\"Numbers:\", nums)\n", + "\n", + "# Tuple can't be modified\n", + "try:\n", + " t[0] = 100\n", + "except:\n", + " print(\"Cannot modify tuple\")\n", + "\n", + "t2 = (9, 8)\n", + "print(\"Concatenated:\", t + t2)\n" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "sLLipOrNMVbM", + "outputId": "e73a1091-8d4b-4999-deca-eaf78c84b2b1" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Numbers: [1, 5, 10.5, 3]\n", + "Cannot modify tuple\n", + "Concatenated: (1, 'a', 5, 10.5, 3, 9, 8)\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "d = {\"Rahul\": 80, \"Priya\": 90}\n", + "\n", + "d[\"Amit\"] = 70\n", + "d[\"Rahul\"] = 85\n", + "del d[\"Priya\"]\n", + "\n", + "print(\"Keys:\", d.keys())\n", + "print(\"Values:\", d.values())\n", + "print(\"Items:\", d.items())" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "E7inXxH6Ma_N", + "outputId": "1aef8541-2921-4ea1-9611-cbf37edefd8f" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Keys: dict_keys(['Rahul', 'Amit'])\n", + "Values: dict_values([85, 70])\n", + "Items: dict_items([('Rahul', 85), ('Amit', 70)])\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "list = [\"madam\", \"hello\", \"racecar\", \"python\"]\n", + "\n", + "sorted_lst = sorted(lst, key=len)\n", + "print(\"Sorted:\", sorted_lst)\n", + "\n", + "pal = [x for x in lst if x == x[::-1]]\n", + "print(\"Palindromes:\", pal)\n", + "\n", + "new = [x.replace(\" \", \"-\") for x in lst]\n", + "print(\"Hyphen list:\", new)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "dXpnIGKnMzW9", + "outputId": "021fb69e-10cc-4fc2-a939-3b299072dc7b" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Sorted: ['madam', 'hello', 'python', 'racecar']\n", + "Palindromes: ['madam', 'racecar']\n", + "Hyphen list: ['madam', 'hello', 'racecar', 'python']\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "t = (5, 12, 3, 20, \"a\")\n", + "\n", + "lst = [x for x in t if not (type(x) == int and x < 10)]\n", + "\n", + "t = tuple(lst)\n", + "print(\"Result:\", t)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "deHauWJzPrV7", + "outputId": "f84511fe-bc74-48a5-f3ff-1402262dfa1f" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Result: (12, 20, 'a')\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "students = {}\n", + "\n", + "n = int(input(\"Enter number of students: \"))\n", + "\n", + "for i in range(n):\n", + " name = input(\"Name: \")\n", + " marks = int(input(\"Marks: \"))\n", + " students[name] = marks\n", + "\n", + "avg = sum(students.values()) / len(students)\n", + "topper = max(students, key=students.get)\n", + "\n", + "print(\"Average:\", avg)\n", + "print(\"Topper:\", topper)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "V6X0eByMP2NJ", + "outputId": "6af8140e-b6fe-4cde-92df-e6c3deee19b8" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Enter number of students: 2\n", + "Name: swaraj\n", + "Marks: 30\n", + "Name: kiran\n", + "Marks: 40\n", + "Average: 35.0\n", + "Topper: kiran\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "contacts = {}\n", + "\n", + "while True:\n", + " ch = input(\"1.Add 2.Search 3.Delete 4.Show 5.Exit: \")\n", + "\n", + " if ch == \"1\":\n", + " name = input(\"Name: \")\n", + " num = input(\"Number: \")\n", + " contacts[name] = num\n", + " elif ch == \"2\":\n", + " name = input(\"Search: \")\n", + " print(contacts.get(name, \"Not found\"))\n", + " elif ch == \"3\":\n", + " name = input(\"Delete: \")\n", + " contacts.pop(name, None)\n", + " elif ch == \"4\":\n", + " print(contacts)\n", + " else:\n", + " break" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "wV4qmRheRAXM", + "outputId": "f0ec5f55-ed92-4a6b-8d9a-dff548ae4806" + }, + "execution_count": null, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1.Add 2.Search 3.Delete 4.Show 5.Exit: 1\n", + "Name: ikuu\n", + "Number: 56\n", + "1.Add 2.Search 3.Delete 4.Show 5.Exit: 2\n", + "Search: ikuu\n", + "56\n", + "1.Add 2.Search 3.Delete 4.Show 5.Exit: 4\n", + "{'ikuu': '56'}\n", + "1.Add 2.Search 3.Delete 4.Show 5.Exit: 3\n", + "Delete: ikuu\n", + "1.Add 2.Search 3.Delete 4.Show 5.Exit: 5\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "emp = {}\n", + "\n", + "while True:\n", + " ch = input(\"1.Add 2.Remove 3.Show 4.Exit: \")\n", + "\n", + " if ch == \"1\":\n", + " name = input(\"Name: \")\n", + " emp[name] = \"Present\"\n", + " elif ch == \"2\":\n", + " name = input(\"Remove: \")\n", + " emp.pop(name, None)\n", + " elif ch == \"3\":\n", + " print(emp)\n", + " else:\n", + " break" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "G_4ztrhARlYt", + "outputId": "e5d8c79e-ac5b-4cbd-c439-3b7b0b3912fe" + }, + "execution_count": null, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1.Add 2.Remove 3.Show 4.Exit: 1\n", + "Name: ikuu\n", + "1.Add 2.Remove 3.Show 4.Exit: 3\n", + "{'ikuu': 'Present'}\n", + "1.Add 2.Remove 3.Show 4.Exit: 2\n", + "Remove: 1\n", + "1.Add 2.Remove 3.Show 4.Exit: 4\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "students = []\n", + "\n", + "n = int(input(\"Enter count: \"))\n", + "\n", + "for i in range(n):\n", + " name = input(\"Name: \")\n", + " roll = int(input(\"Roll: \"))\n", + " marks = int(input(\"Marks: \"))\n", + " students.append({\"name\": name, \"roll\": roll, \"marks\": marks})\n", + "\n", + "for s in students:\n", + " if s[\"marks\"] >= 40:\n", + " print(s[\"name\"], \"Pass\")\n", + " else:\n", + " print(s[\"name\"], \"Fail\")" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "kqJexREDRueM", + "outputId": "ea0a8d46-9d70-442a-e5c4-b61a10ca488c" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Enter count: 3\n", + "Name: ikuu\n", + "Roll: 164\n", + "Marks: 90\n", + "Name: bravo\n", + "Roll: 123\n", + "Marks: 34\n", + "Name: michel\n", + "Roll: 189\n", + "Marks: 76\n", + "ikuu Pass\n", + "bravo Fail\n", + "michel Pass\n" + ] + } + ] + } + ] +} \ No newline at end of file