├── Python Q&A.pdf ├── PPL_21CSL46.pdf ├── 21CSL46LabManual.pdf ├── pgm1b.py ├── pgm2a.py ├── program1a.py ├── pgm3b.py ├── pgm3a.py ├── SECURITY.md ├── pgm2b.py ├── .github └── workflows │ └── python-package.yml ├── README.md ├── CODE_OF_CONDUCT.md └── LICENSE /Python Q&A.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FarhaKousar1601/21CSL46/HEAD/Python Q&A.pdf -------------------------------------------------------------------------------- /PPL_21CSL46.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FarhaKousar1601/21CSL46/HEAD/PPL_21CSL46.pdf -------------------------------------------------------------------------------- /21CSL46LabManual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FarhaKousar1601/21CSL46/HEAD/21CSL46LabManual.pdf -------------------------------------------------------------------------------- /pgm1b.py: -------------------------------------------------------------------------------- 1 | val = int(input("Enter a value : ")) 2 | str_val = str(val) 3 | if str_val == str_val[::-1]: 4 | print("Palindrome") 5 | else: 6 | print("Not Palindrome") 7 | for i in range(10): 8 | if str_val.count(str(i)) > 0: 9 | print(str(i),"appears", str_val.count(str(i)), "times"); -------------------------------------------------------------------------------- /pgm2a.py: -------------------------------------------------------------------------------- 1 | def fn(n): 2 | if n == 1: 3 | return 0 4 | elif n == 2: 5 | return 1 6 | else: 7 | return fn(n - 1) + fn(n - 2) 8 | num = int(input("Enter a number :")) 9 | if num > 0: 10 | print("fn(", num, ") = ", fn(num), sep="") 11 | else: 12 | print("Error in input") 13 | -------------------------------------------------------------------------------- /program1a.py: -------------------------------------------------------------------------------- 1 | m1 = int(input("Enter marks for test1 : ")) 2 | m2 = int(input("Enter marks for test2 : ")) 3 | m3 = int(input("Enter marks for test3 : ")) 4 | if m1 <= m2 and m1 <= m3: 5 | avgMarks = (m2+m3)/2 6 | elif m2 <= m1 and m2 <= m3: 7 | avgMarks = (m1+m3)/2 8 | elif m3 <= m1 and m2 <= m2: 9 | avgMarks = (m1+m2)/2 10 | print("Average of best two test marks out of three test’s marks is", avgMarks); 11 | -------------------------------------------------------------------------------- /pgm3b.py: -------------------------------------------------------------------------------- 1 | str1 = input("Enter a string 1\n: ") 2 | str2 = input("Enter string mis2\n : ") 3 | if len(str1) < len(str2): 4 | short = len(str2) 5 | long = len(str1) 6 | 7 | else: 8 | short = len(str1) 9 | long = len(str1) 10 | 11 | matchcnt = 0 12 | for i in range(short): 13 | if str1[i] == str2[i]: 14 | matchcnt += 1 15 | print("similarity between two strings :") 16 | print(matchcnt/long) -------------------------------------------------------------------------------- /pgm3a.py: -------------------------------------------------------------------------------- 1 | sentence = input("Enter a sentence :") 2 | wordsList = sentence.split(" ") 3 | print("This sentence has", len(wordsList), "words") 4 | digcnt = upcnt = locnt = 0 5 | for ch in sentence: 6 | if '0' <= ch <= '9': 7 | digcnt += 1 8 | elif 'A' <= ch <= 'Z': 9 | upcnt += 1 10 | elif 'a' <= ch <= 'z': 11 | locnt += 1 12 | print("This sentence has", digcnt, "digits,", upcnt, "upper case letters and", locnt, "lower case letters") 13 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | Use this section to tell people about which versions of your project are 6 | currently being supported with security updates. 7 | 8 | | Version | Supported | 9 | | ------- | ------------------ | 10 | | 5.1.x | :white_check_mark: | 11 | | 5.0.x | :x: | 12 | | 4.0.x | :white_check_mark: | 13 | | < 4.0 | :x: | 14 | 15 | ## Reporting a Vulnerability 16 | 17 | Use this section to tell people how to report a vulnerability. 18 | 19 | Tell them where to go, how often they can expect to get an update on a 20 | reported vulnerability, what to expect if the vulnerability is accepted or 21 | declined, etc. 22 | -------------------------------------------------------------------------------- /pgm2b.py: -------------------------------------------------------------------------------- 1 | def bin2Dec(val): 2 | rev=val[::-1] 3 | dec = 0 4 | i = 0 5 | for dig in rev: 6 | dec += int(dig) * 2**i 7 | i += 1 8 | 9 | return dec 10 | 11 | 12 | 13 | def oct2Hex(val): 14 | rev = val[::-1] 15 | dec = 0 16 | i = 0 17 | for dig in rev: 18 | dec += int(dig) * 8 ** i 19 | i += 1 20 | 21 | hex_val = "" # Initialize an empty string to store the hexadecimal result 22 | 23 | while dec != 0: 24 | remainder = dec % 16 # Calculate the remainder when dividing by 16 25 | if remainder <= 9: 26 | hex_digit = str(remainder) # Convert remainder to a string for hex representation 27 | else: 28 | hex_digit = chr(ord('A') + remainder - 10) # Convert to hex letter (A-F) 29 | hex_val = hex_digit + hex_val # Add the hex digit to the result 30 | dec = dec // 16 # Integer division to continue the process 31 | 32 | return hex_val 33 | num1 = input("Enter a binary number : ") 34 | print(bin2Dec(num1)) 35 | num2 = input("Enter a octal number : ") 36 | print(oct2Hex(num2)) -------------------------------------------------------------------------------- /.github/workflows/python-package.yml: -------------------------------------------------------------------------------- 1 | - name: Setup Python 2 | uses: actions/setup-python@v4.7.0 3 | with: 4 | # Version range or exact version of Python or PyPy to use, using SemVer's version range syntax. Reads from .python-version if unset. 5 | python-version: # optional 6 | # File containing the Python version to use. Example: .python-version 7 | python-version-file: # optional 8 | # Used to specify a package manager for caching in the default directory. Supported values: pip, pipenv, poetry. 9 | cache: # optional 10 | # The target architecture (x86, x64) of the Python or PyPy interpreter. 11 | architecture: # optional 12 | # Set this option if you want the action to check for the latest available version that satisfies the version spec. 13 | check-latest: # optional 14 | # The token used to authenticate when fetching Python distributions from https://github.com/actions/python-versions. When running this action on github.com, the default value is sufficient. When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting. 15 | token: # optional, default is ${{ github.server_url == 'https://github.com' && github.token || '' }} 16 | # Used to specify the path to dependency files. Supports wildcards or a list of file names for caching multiple dependencies. 17 | cache-dependency-path: # optional 18 | # Set this option if you want the action to update environment variables. 19 | update-environment: # optional, default is true 20 | # When 'true', a version range passed to 'python-version' input will match prerelease versions if no GA versions are found. Only 'x.y' version range is supported for CPython. 21 | allow-prereleases: # optional 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Python 21CSL46](https://img.shields.io/badge/Python-21CSL46-blue?style=for-the-badge&logo=python)](#) 2 | 3 | # Python Programming Laboratory (21CSL46) 4 | 5 | 6 | 7 | The Python Programming Laboratory course (21CSL46) introduces students to Python fundamentals, data types, flow control, functions, and object-oriented programming. It covers regular expressions, file handling, and working with Excel, PDF, Word, and JSON files. CIE and SEE assessments ensure comprehensive learning and practical application. 8 | 9 | ## Course Overview 10 | 11 | 1. **Python Fundamentals and Flow Control:** 12 | - Write Python programs to find the best of two test average marks and check for palindromes: 13 | 1. Introduce the Python fundamentals, data types, operators, flow control and exception handling in Python 14 | (a) Write a python program to find the best of two test average marks out of three test’s marks accepted from the user. 15 | (b) Develop a Python program to check whether a given number is palindrome or not and also count the number of occurrences of each digit in the input number. 16 | 17 | 18 | 2. **Functions and Parameters:** 19 | - Implement functions to calculate Fibonacci numbers and convert between number systems: 20 | 2. Demonstrating creation of functions, passing parameters and return values 21 | (a) Defined as a function F as Fn = Fn-1 + Fn-2. Write a Python program which accepts a value for N (where N > 0) as input and pass this value to the function. Display suitable error message if the condition for input value is not followed. 22 | 23 | (b) Develop a python program to convert binary to decimal, octal to hexadecimal using functions. 24 | 25 | 3. **String Manipulation:** 26 | - Develop programs to analyze sentences and compare string similarity: 27 | 3. Demonstration of manipulation of strings using string methods 28 | (a) Write a Python program that accepts a sentence and find the number of words, digits, uppercase letters and lowercase letters. 29 | (b) Write a Python program to find the string similarity between two given strings 30 | Sample Output: Sample Output: 31 | Original string: Original string: 32 | Python Exercises Python Exercises 33 | Python Exercises Python Exercise 34 | Similarity between two said strings: Similarity between two said strings: 35 | 1.0 0.967741935483871 36 | 37 | 4. **Collections:** 38 | - Explore lists, tuples, and dictionaries to implement sorting algorithms and convert Roman numerals: 39 | 4. Discuss different collections like list, tuple and dictionary 40 | (a) Write a python program to implement insertion sort and merge sort using lists 41 | (b) Write a program to convert roman numbers in to integer values using dictionaries. 42 | 43 | 44 | 5. **Pattern Recognition:** 45 | - Create functions to recognize patterns and search for phone numbers and email addresses: 46 | 5. Demonstration of pattern recognition with and without using regular expressions 47 | (a) Write a function called isphonenumber () to recognize a pattern 415-555-4242 without using regular expression and also write the code to recognize the same pattern 48 | (b) Develop a python program that could search the text in a file for phone numbers (+919900889977) and email addresses (sample@gmail.com) 49 | 50 | 6. **File Operations:** 51 | - Perform operations on files, including reading, writing, and organizing data. Create ZIP files: 52 | 6. Demonstration of reading, writing and organizing files. 53 | (a) Write a python program to accept a file name from the user and perform the following operations 54 | 1. Display the first N line of the file 55 | 2. Find the frequency of occurrence of the word accepted from the user in the file 56 | (b) Write a python program to create a ZIP file of a particular folder which contains several files inside it. 57 | 58 | 7. **Object-Oriented Programming:** 59 | - Utilize inheritance to find areas of geometric shapes and manage employee details: 60 | 7. Demonstration of the concepts of classes, methods, objects and inheritance 61 | (a) By using the concept of inheritance write a python program to find the area of triangle, circle and rectangle. 62 | (b) Write a python program by creating a class called Employee to store the details of Name, Employee_ID, Department and Salary, and implement a method to update salary of employees belonging to a given department. 63 | 64 | 8. **Polymorphism and Overriding:** 65 | - Implement polymorphic functions to check palindromes: 66 | 8. Demonstration of classes and methods with polymorphism and overriding 67 | (a) Write a python program to find the whether the given input is palindrome or not (for both string and integer) using the concept of polymorphism and inheritance. 68 | 69 | 9. **Data Handling:** 70 | - Download XKCD comics and manipulate spreadsheet data: 71 | 9. Demonstration of working with excel spreadsheets and web scraping 72 | (a) Write a python program to download the all XKCD comics 73 | (b) Demonstrate python program to read the data from the spreadsheet and write the data in to the spreadsheet 74 | 75 | 10. **File Formats:** 76 | - Combine PDF pages and fetch weather data from JSON files: 77 | 10. Demonstration of working with PDF, word and JSON files 78 | (a) Write a python program to combine select pages from many PDFs 79 | (b) Write a python program to fetch current weather data from the JSON file 80 | 81 | ## Assessment 82 | This course includes continuous internal evaluation (CIE) and semester-end examination (SEE) to ensure comprehensive learning and practical application. 83 | 84 | Thank you for visiting the OpenLearnHub organization to learn Python Lab for the 4th semester under the 2021 scheme of VTU. 85 | 86 | Happy learning! 87 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | farhakousar1601@gmail.com. 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at 128 | https://www.contributor-covenant.org/translations. 129 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Creative Commons Legal Code 2 | 3 | CC0 1.0 Universal 4 | 5 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE 6 | LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN 7 | ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS 8 | INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES 9 | REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS 10 | PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM 11 | THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED 12 | HEREUNDER. 13 | 14 | Statement of Purpose 15 | 16 | The laws of most jurisdictions throughout the world automatically confer 17 | exclusive Copyright and Related Rights (defined below) upon the creator 18 | and subsequent owner(s) (each and all, an "owner") of an original work of 19 | authorship and/or a database (each, a "Work"). 20 | 21 | Certain owners wish to permanently relinquish those rights to a Work for 22 | the purpose of contributing to a commons of creative, cultural and 23 | scientific works ("Commons") that the public can reliably and without fear 24 | of later claims of infringement build upon, modify, incorporate in other 25 | works, reuse and redistribute as freely as possible in any form whatsoever 26 | and for any purposes, including without limitation commercial purposes. 27 | These owners may contribute to the Commons to promote the ideal of a free 28 | culture and the further production of creative, cultural and scientific 29 | works, or to gain reputation or greater distribution for their Work in 30 | part through the use and efforts of others. 31 | 32 | For these and/or other purposes and motivations, and without any 33 | expectation of additional consideration or compensation, the person 34 | associating CC0 with a Work (the "Affirmer"), to the extent that he or she 35 | is an owner of Copyright and Related Rights in the Work, voluntarily 36 | elects to apply CC0 to the Work and publicly distribute the Work under its 37 | terms, with knowledge of his or her Copyright and Related Rights in the 38 | Work and the meaning and intended legal effect of CC0 on those rights. 39 | 40 | 1. Copyright and Related Rights. A Work made available under CC0 may be 41 | protected by copyright and related or neighboring rights ("Copyright and 42 | Related Rights"). Copyright and Related Rights include, but are not 43 | limited to, the following: 44 | 45 | i. the right to reproduce, adapt, distribute, perform, display, 46 | communicate, and translate a Work; 47 | ii. moral rights retained by the original author(s) and/or performer(s); 48 | iii. publicity and privacy rights pertaining to a person's image or 49 | likeness depicted in a Work; 50 | iv. rights protecting against unfair competition in regards to a Work, 51 | subject to the limitations in paragraph 4(a), below; 52 | v. rights protecting the extraction, dissemination, use and reuse of data 53 | in a Work; 54 | vi. database rights (such as those arising under Directive 96/9/EC of the 55 | European Parliament and of the Council of 11 March 1996 on the legal 56 | protection of databases, and under any national implementation 57 | thereof, including any amended or successor version of such 58 | directive); and 59 | vii. other similar, equivalent or corresponding rights throughout the 60 | world based on applicable law or treaty, and any national 61 | implementations thereof. 62 | 63 | 2. Waiver. To the greatest extent permitted by, but not in contravention 64 | of, applicable law, Affirmer hereby overtly, fully, permanently, 65 | irrevocably and unconditionally waives, abandons, and surrenders all of 66 | Affirmer's Copyright and Related Rights and associated claims and causes 67 | of action, whether now known or unknown (including existing as well as 68 | future claims and causes of action), in the Work (i) in all territories 69 | worldwide, (ii) for the maximum duration provided by applicable law or 70 | treaty (including future time extensions), (iii) in any current or future 71 | medium and for any number of copies, and (iv) for any purpose whatsoever, 72 | including without limitation commercial, advertising or promotional 73 | purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each 74 | member of the public at large and to the detriment of Affirmer's heirs and 75 | successors, fully intending that such Waiver shall not be subject to 76 | revocation, rescission, cancellation, termination, or any other legal or 77 | equitable action to disrupt the quiet enjoyment of the Work by the public 78 | as contemplated by Affirmer's express Statement of Purpose. 79 | 80 | 3. Public License Fallback. Should any part of the Waiver for any reason 81 | be judged legally invalid or ineffective under applicable law, then the 82 | Waiver shall be preserved to the maximum extent permitted taking into 83 | account Affirmer's express Statement of Purpose. In addition, to the 84 | extent the Waiver is so judged Affirmer hereby grants to each affected 85 | person a royalty-free, non transferable, non sublicensable, non exclusive, 86 | irrevocable and unconditional license to exercise Affirmer's Copyright and 87 | Related Rights in the Work (i) in all territories worldwide, (ii) for the 88 | maximum duration provided by applicable law or treaty (including future 89 | time extensions), (iii) in any current or future medium and for any number 90 | of copies, and (iv) for any purpose whatsoever, including without 91 | limitation commercial, advertising or promotional purposes (the 92 | "License"). The License shall be deemed effective as of the date CC0 was 93 | applied by Affirmer to the Work. Should any part of the License for any 94 | reason be judged legally invalid or ineffective under applicable law, such 95 | partial invalidity or ineffectiveness shall not invalidate the remainder 96 | of the License, and in such case Affirmer hereby affirms that he or she 97 | will not (i) exercise any of his or her remaining Copyright and Related 98 | Rights in the Work or (ii) assert any associated claims and causes of 99 | action with respect to the Work, in either case contrary to Affirmer's 100 | express Statement of Purpose. 101 | 102 | 4. Limitations and Disclaimers. 103 | 104 | a. No trademark or patent rights held by Affirmer are waived, abandoned, 105 | surrendered, licensed or otherwise affected by this document. 106 | b. Affirmer offers the Work as-is and makes no representations or 107 | warranties of any kind concerning the Work, express, implied, 108 | statutory or otherwise, including without limitation warranties of 109 | title, merchantability, fitness for a particular purpose, non 110 | infringement, or the absence of latent or other defects, accuracy, or 111 | the present or absence of errors, whether or not discoverable, all to 112 | the greatest extent permissible under applicable law. 113 | c. Affirmer disclaims responsibility for clearing rights of other persons 114 | that may apply to the Work or any use thereof, including without 115 | limitation any person's Copyright and Related Rights in the Work. 116 | Further, Affirmer disclaims responsibility for obtaining any necessary 117 | consents, permissions or other rights required for any use of the 118 | Work. 119 | d. Affirmer understands and acknowledges that Creative Commons is not a 120 | party to this document and has no duty or obligation with respect to 121 | this CC0 or use of the Work. 122 | --------------------------------------------------------------------------------