{"id":249,"date":"2025-04-15T15:58:42","date_gmt":"2025-04-15T15:58:42","guid":{"rendered":"https:\/\/sites.wp.odu.edu\/eportfoliocyse\/?page_id=249"},"modified":"2025-04-15T15:58:42","modified_gmt":"2025-04-15T15:58:42","slug":"intro-to-python-programming-cs-153","status":"publish","type":"page","link":"https:\/\/sites.wp.odu.edu\/eportfoliocyse\/intro-to-python-programming-cs-153\/","title":{"rendered":"Intro. to Python Programming (CS 153)"},"content":{"rendered":"\n<pre class=\"wp-block-preformatted\">I enrolled into the Intro Programming with Python (CS 153) course in Spring 2024. This course taught me how to program in Python and learned the skill of repetition and how it helped me refine my skills in coding. One coding assignment that stood out among the others was that we were prompted to create a \u201clibrary management\u201d that would tell the user what was checked out, what was added to the library, and what was in stock. This assignment was challenging in many ways, but with help from the professor and assistants, I was able to fully understand and complete the task at hand. In the professional world, I would consider this as a skill of persistence, in which I will keep working and try to get help if necessary.<\/pre>\n\n\n\n<p>Below is the python file (written out due to WordPress formatting) of the program &#8220;Library Management&#8221;:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># -*- coding: utf-8 -*-\r\n\"\"\"\r\nName of source file: Exercise_11-Task2-ABRAHAM_PEREZ.py\r\nStudent name: Abraham Perez\r\n\r\nDate: Fri Mar 29 2024\r\n\r\nThis program is used to upgrade a library management system to utilize a nested\r\ndictionary instead of the list.\r\n\"\"\"\r\n\r\nbooks= {\r\n        \"Harry Potter\": {\"copies\": 5, \"loaned\": 0, \"loaned_to\":[]},\r\n        \"Lord of the rings\": {\"copies\": 3, \"loaned\": 0, \"loaned_to\":[]},\r\n        \"Pride and Prejudice\": {\"copies\": 4, \"loaned\": 0, \"loaned_to\":[]},\r\n        #additional books here\r\n        }\r\nloaned_books_count= 0\r\n\r\n#add_book function uses if statement for when a title is not in dictionary, \r\n#and uses else and increases copies number\r\ndef add_book(title, copies):\r\n    if title not in books:\r\n        books[title]= {'copies': copies, 'loaned': 0, 'loaned_to': []}\r\n    else:\r\n        books[title][\"copies\"] += copies\r\n    print(f\"Added '{copies}' copies of {title} to the library.\")\r\n    \r\n#loan_out function checks if book can be loaned out to someone, and enters name to loaned_to list, \r\n#and if not print stating it's not available for loan\r\ndef loan_out(title, borrower_name):\r\n    \r\n    if title in books:\r\n        books[title][\"loaned\"] += 1\r\n        books[title][\"loaned_to\"].append(borrower_name)\r\n        print(f\"Loaned out '{title}' to '{borrower_name}'.\")\r\n        return True\r\n    else:\r\n        print(f'Book {title} is not available for loan.')\r\n        return False\r\n        \r\n#return_book function checks if book can be returned, \r\n#if not prints that it can't and it wasn't loaned to borrower\r\ndef return_book(title, borrower_name):\r\n    if title in books and borrower_name in books[title][\"loaned_to\"]:\r\n        books[title][\"loaned\"] -= 1\r\n        books[title][\"loaned_to\"].remove(borrower_name)\r\n        print(f\"'{borrower_name}' has returned '{title}'.\")\r\n    else:\r\n        print(f\"Can't return '{title}'. It was not loaned out to '{borrower_name}'.\")\r\n\r\n#display_inventory function displays all titles, number of copies, and how many were loaned\r\ndef display_inventory():\r\n    for title, info in books.items():\r\n        print(f'{title}, Copies: {info[\"copies\"]} Loaned: {info[\"loaned\"]}')\r\n\r\n#display_loan_history function prints if any books have been loaned out to,\r\n#if not, prints that all copies are available\r\ndef display_loan_history():\r\n    for title, info in books.items():\r\n        borrowers= ', '.join(info['loaned_to'])\r\n        if borrowers:\r\n            print(f\"'{title}' has been loaned out to: {borrowers}\")\r\n        else:\r\n            print(f\"All '{title}' copies are available.\")\r\n\r\n#search_for_book function checks if book is alrady in dictionary,\r\n#if not, prints that it can't be found\r\ndef search_for_book(query):\r\n    found= False\r\n    for title in books.keys():\r\n        if query.lower() in title.lower():\r\n            available= books[title][\"copies\"] - books[title][\"loaned\"]\r\n            borrowers= ', '.join(books[title]['loaned_to'])\r\n            print(f\"'{title}' - Available Copies: {available}, Borrowers: {borrowers}\")\r\n            found= True\r\n    if not found:\r\n        print(f\"No books matching '{query}' is found in the library inventory.\")\r\n\r\n\r\n#Sample run\r\nadd_book(\"The Hobbit\", 2)\r\nprint(50*\"*\")\r\nloan_out(\"Harry Potter\", \"Alice\")\r\nprint(50*\"*\")\r\nloan_out(\"Pride and Prejudice\", \"Bob\")\r\nprint(50*\"*\")\r\nreturn_book(\"Harry Potter\", \"Alice\")\r\nprint(50*\"*\")\r\ndisplay_inventory()\r\nprint(50*\"*\")\r\ndisplay_loan_history()\r\nprint(50*\"*\")\r\nsearch_for_book(\"Pride\")\r\nprint(50*\"*\")\r\nsearch_for_book(\"The Great Gatsby\")\r\nprint(50*\"*\")\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I enrolled into the Intro Programming with Python (CS 153) course in Spring 2024. This course taught me how to program in Python and learned the skill of repetition and how it helped me refine my skills in coding. One&#8230; <a class=\"more-link\" href=\"https:\/\/sites.wp.odu.edu\/eportfoliocyse\/intro-to-python-programming-cs-153\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":23778,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"_links":{"self":[{"href":"https:\/\/sites.wp.odu.edu\/eportfoliocyse\/wp-json\/wp\/v2\/pages\/249"}],"collection":[{"href":"https:\/\/sites.wp.odu.edu\/eportfoliocyse\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/sites.wp.odu.edu\/eportfoliocyse\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/sites.wp.odu.edu\/eportfoliocyse\/wp-json\/wp\/v2\/users\/23778"}],"replies":[{"embeddable":true,"href":"https:\/\/sites.wp.odu.edu\/eportfoliocyse\/wp-json\/wp\/v2\/comments?post=249"}],"version-history":[{"count":1,"href":"https:\/\/sites.wp.odu.edu\/eportfoliocyse\/wp-json\/wp\/v2\/pages\/249\/revisions"}],"predecessor-version":[{"id":250,"href":"https:\/\/sites.wp.odu.edu\/eportfoliocyse\/wp-json\/wp\/v2\/pages\/249\/revisions\/250"}],"wp:attachment":[{"href":"https:\/\/sites.wp.odu.edu\/eportfoliocyse\/wp-json\/wp\/v2\/media?parent=249"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}