0% found this document useful (0 votes)
3 views14 pages

Correction and Outputs

The document provides an overview of Python and SQLite, highlighting their features and applications in programming and database management. Python is a versatile, high-level language used for various applications, while SQLite is a lightweight, serverless database engine ideal for small to medium-sized applications. The document also includes example programs demonstrating arithmetic operations, perfect numbers, Armstrong numbers, factorial calculations, Fibonacci series, palindrome checks, and file handling utilities.

Uploaded by

zack099king
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views14 pages

Correction and Outputs

The document provides an overview of Python and SQLite, highlighting their features and applications in programming and database management. Python is a versatile, high-level language used for various applications, while SQLite is a lightweight, serverless database engine ideal for small to medium-sized applications. The document also includes example programs demonstrating arithmetic operations, perfect numbers, Armstrong numbers, factorial calculations, Fibonacci series, palindrome checks, and file handling utilities.

Uploaded by

zack099king
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Python

Python is a high-level, interpreted programming language


known for its simplicity and readability. Developed by Guido

van Rossum and first released in 1991, Python is widely

used in various fields, including web development, data

science, automation, and software development. It is

known for its easy-to-understand syntax, which

emphasizes readability and reduces the complexity of

writing code. Python supports multiple programming

paradigms, including procedural, object-oriented, and

functional programming.

In this project, Python serves as the core language to

implement the logic and functionality of the Library


Management System. The powerful libraries and modules
available in Python, such as sqlite3, make it an ideal choice

for building such applications. Python is also platform-

independent, meaning it can run on various operating

systems such as Windows, macOS, and Linux.

Python’s extensive libraries and frameworks allow

developers to quickly build applications, as seen in this

project, where it connects to and interacts with a database,

handles user inputs, and manages data efficiently.


SQLite

SQLite is a self-contained, serverless, and zero-


configuration database engine that is widely used in

embedded systems, mobile applications, and small to

medium-sized desktop applications. Unlike other database

management systems (DBMS) like MySQL or PostgreSQL,

SQLite does not require a separate server process or

system to operate. Instead, it stores data in a single file on

the local file system, making it lightweight and easy to

integrate into applications.

SQLite is an open-source software that is used in many

mobile apps, web browsers, and even desktop applications,

like web browsers and applications that require a small,

local database. In this project, SQLite is used to store and

manage data related to books, their availability, and the

issue and return details of library books.

The sqlite3 module in Python allows seamless integration


between Python and SQLite databases. It helps in

connecting to the SQLite database, creating tables,

executing SQL queries, and fetching data. SQLite's

simplicity makes it an ideal choice for small to medium-

sized applications like this one, where a full-fledged DBMS

is not required.
Output
Program - 1
Example Output:
Enter the first number: 10
Enter the second number: 2

Arithmetic Operations:
10.0 + 2.0 = 12.0
10.0 - 2.0 = 8.0
10.0 * 2.0 = 20.0
10.0 / 2.0 = 5.0
10.0 % 2.0 = 0.0

Program - 2
Example Output:
Case 1 (Perfect Number):
Enter a number to check if it is perfect: 28
28 is a perfect number.

Case 2 (Not a Perfect Number):


Enter a number to check if it is perfect: 15
15 is not a perfect number.

Explanation:
• 28 is a perfect number because its proper divisors are 1, 2, 4, 7, 14, and
their sum is 28.
• If the sum of proper divisors is not equal to the number, it is not a
perfect number.
Output
Program – 3
Example Output:
Case 1 (Armstrong Number):
Enter a number to check if it is an Armstrong number: 153
153 is an Armstrong number.

Case 2 (Not an Armstrong Number):


Enter a number to check if it is an Armstrong number: 123
123 is not an Armstrong number.

Explanation:
• 153 is an Armstrong number because 13+53+33=1531^3 + 5^3 + 3^3 =
15313+53+33=153.
• If the sum of the digits raised to the power of the number of digits is
not equal to the number, it is not an Armstrong number.
Program – 4
Example Output:
Case 1 (Positive Number):
Enter a number to find its factorial: 5
The factorial of 5 is 120.

Case 1 (Zero):
Enter a number to find its factorial: 0
The factorial of 0 is 1.
Output
Case 3 (Negative Number):
Enter a number to find its factorial: -3
Factorial is not defined for negative numbers.

Explanation:
• Factorial of n is the product of all positive integers less than or equal
to n.
• n! = n × (n−1) × (n−2) ⋯ ×1
• For n=0, 0! is defined as 1.

Program – 5
Example Output:
Case 1 (Positive Number):
Enter the number of terms for the Fibonacci series: 7
The first 7 terms of the Fibonacci series are: [0, 1, 1, 2,
3, 5, 8]

Case 2 (Invalid Input):


Enter the number of terms for the Fibonacci series: -3
Please enter a positive integer.

Explanation:
• Fibonacci Series starts with 0 and 1, and each subsequent term is the
sum of the previous two terms: F(n)=F(n−1)+F(n−2)
• The series starts as: 0, 1, 1, 2, 3, 5, 8, ...
Output
Example Output:
Case 1 (Palindrome):
Enter a string to check if it is a palindrome: madam
"madam" is a palindrome.

Case 2 (Not a Palindrome):


Enter a string to check if it is a palindrome: hello
"hello" is not a palindrome.

Case 3 (Case Insensitive Palindrome):


Enter a string to check if it is a palindrome: RaceCar
"RaceCar" is a palindrome.

Explanation:
1. Palindrome: A string is a palindrome if it reads the same backward as
forward.
2. Loop Logic: Compare characters from the start and end of the string
using a loop until the middle of the string is reached.
3. Case-insensitive check: Convert the string to lowercase to ensure the
comparison is not case-sensitive.
Output
Example Output:
Case 1: Numeric Input
Enter a list of elements separated by spaces: 5 3 8 2 5 10
Operations on the list:
Original list: [5, 3, 8, 2, 5, 10]
Length of the list: 6
Sorted list (if all items are numeric): [2, 3, 5, 5, 8, 10]
Maximum value (if numeric): 10
Minimum value (if numeric): 2
Reversed list: [10, 5, 2, 8, 3, 5]
Unique elements: [2, 3, 5, 8, 10]

Case 2: Mixed Input


Enter a list of elements separated by spaces: apple 3 banana
3.5 cherry
Operations on the list:
Original list: ['apple', 3, 'banana', 3.5, 'cherry']
Length of the list: 5
Sorted list (if all items are numeric): Sorting not possible
Maximum value (if numeric): N/A
Minimum value (if numeric): N/A
Reversed list: ['cherry', 3.5, 'banana', 3, 'apple']
Unique elements: ['banana', 'cherry', 3, 3.5, 'apple']

Explanation:
• Input Handling: The input is split into individual elements and converted to
integers, floats, or kept as strings.
• Operations:
• Display the original list.
• Find the length of the list.
• Sort the list if it contains only numeric elements.
• Find the maximum and minimum values if numeric.
• Reverse the list.
• Display unique elements.
Output
Example Usage:
Input:
1. Enter file name: example.txt
2. Menu options allow you to:
• Read content.
• Append data to the file.
• Write data (overwriting existing content).
• View statistics like number of lines, words, and characters.

Example Output:
File Handling Utility in Python
Enter the file name: example.txt

Menu:
1. Read file content
2. Append data to the file
3. Write data to the file
4. Show file statistics
5. Exit
Enter your choice (1-5): 1

File Content:
Hello, this is a sample file.

Menu:
Enter your choice (1-5): 4

File Statistics:
Number of lines: 1
Number of words: 6
Number of characters: 30

Key Features:
1. Read file content: Display the content of the file.
2. Append data: Add new content without overwriting existing data.
3. Write data: Overwrite the file with new data.
4. File statistics: Count lines, words, and characters in the file.
5. Error handling: Handles cases where the file doesn't exist or other unexpected
errors occur.
Output
Example Output:
Case 1: File with Content
Suppose the file example.txt contains the following content:

This is a sample file. This file is for testing word


occurrences. The word file appears multiple times.

Input:
Enter the file name: example.txt
Enter the word to count occurrences of: file

Output:
The word "file" occurs 3 times in the file "example.txt".

Case 2: File Not Found


Input:
Enter the file name: nonexistent.txt
Enter the word to count occurrences of: file

Output:
Error:the
Enter Thefile
filename:
'nonexistent.txt'
nonexistent.txt
does not exist.
Enter the word to count occurrences of: file
Output
Example Output:
Case 1: Word with vowels
Input:
Enter a word: beautiful

Output:
Unique vowels in 'beautiful' are: ['e', 'a', 'u', 'i']

Case 2: Word with no vowels


Input:
Enter a word: rhythm

Output:
No vowels found in 'rhythm'.

Explanation:
1. Stack Usage: The program uses a list as a stack to store vowels. Only unique
vowels are added to the stack.
2. Case Insensitivity: The input word is converted to lowercase to ensure vowels are
matched correctly regardless of case.
3. Logic:
• Loop through each character in the word.
• If the character is a vowel (a, e, i, o, u) and not already in the stack, push it
onto the stack.
4. Result: The stack contains all the unique vowels in the order they appear in the
word.
Output
Example Usage:
Case 1: Adding Records

Student Record Management System


1. Add Student
2. View Students
3. Search Student
4. Delete Student
5. Exit
Enter your choice (1-5): 1
Enter Roll Number: 101
Enter Name: John Doe
Enter Grade: A
Student record added successfully.

Case 2: Viewing Records


Student Record Management System
Enter your choice (1-5): 2

Student Records:
Roll No Name Grade
------------------------------
101 John Doe A

Case 3: Searching Records


Enter your choice (1-5): 3
Enter Roll Number to search: 101

Student Record Found:


Roll No: 101, Name: John Doe, Grade: A
Output
Case 4: Deleting Records
Enter your choice (1-5): 4
Enter Roll Number to delete: 101
Student record deleted successfully.

Explanation:
1. File Handling: The program uses the student_records.txt file to store
and retrieve student records.
2. Modular Design: Each operation (add, view, search, delete) is
implemented as a separate function for clarity.
3. Error Handling: Ensures the program doesn’t crash if the file doesn’t
exist or if invalid input is provided.
Output
Example Input/Output:
Enter the number up to which prime numbers are to be
generated: 20
Prime numbers up to 20: [2, 3, 5, 7, 11, 13, 17, 19]
Output
Example Input/Output:
Case 1: Two Positive Numbers
Input:
Enter the first number: 56
Enter the second number: 98

Output:
The GCD of 56 and 98 is: 14

Case 2: One Number is Zero


Input:
Enter the first number: 0
Enter the second number: 25

Output:
The GCD of 0 and 25 is: 25

Explanation:
1. Euclidean Algorithm:
• The GCD of two numbers a and b is calculated by repeatedly replacing a
with b and b with a % b (remainder of a divided by b) until b becomes 0.
• At this point, a contains the GCD.
2. Handling Zero:
• If one number is zero, the GCD is the other number (e.g., GCD(0, 25) = 25).

You might also like