0% found this document useful (0 votes)
1 views12 pages

Python Problem 1

The document outlines three problem statements: a Log File Analyzer that counts log messages of different severity levels, a Data Report Generator that processes and summarizes employee data from a CSV file, and a Bank Account System that allows users to manage their account balance with deposit and withdrawal functionalities. Each section includes algorithms, main code examples, and expected outputs to illustrate the functionality of the programs. The overall goal is to simplify data handling and improve user interaction with applications.

Uploaded by

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

Python Problem 1

The document outlines three problem statements: a Log File Analyzer that counts log messages of different severity levels, a Data Report Generator that processes and summarizes employee data from a CSV file, and a Bank Account System that allows users to manage their account balance with deposit and withdrawal functionalities. Each section includes algorithms, main code examples, and expected outputs to illustrate the functionality of the programs. The overall goal is to simplify data handling and improve user interaction with applications.

Uploaded by

rshrimathi0106
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PROBLEM STATEMENT -I

LOG FILE ANALYZER USING PYTHON

1. Problem Statement
System log files contain important information about the activities and problems occurring in an
application. When a log file becomes large, manually checking every line is difficult and time-
consuming. The aim of this program is to read a log file and count how many INFO, WARNING,
ERROR, and CRITICAL messages are present. The program then displays a simple summary,
making it easier to understand the overall condition of the system.

2. Sample Log Data


2026-07-12 09:00:15 INFO User Login Successful
2026-07-12 09:01:10 WARNING Low Disk Space
2026-07-12 09:01:35 INFO File Uploaded
2026-07-12 09:02:00 ERROR Database Connection Failed
2026-07-12 09:02:45 INFO Database Reconnected
2026-07-12 09:03:20 WARNING High Memory Usage
2026-07-12 09:04:10 ERROR File Not Found
2026-07-12 09:05:00 CRITICAL Server Crash
2026-07-12 09:06:30 INFO Application Closed

3. Algorithm
 Step 1: Start the program.
 Step 2: Import Counter from the collections module.
 Step 3: Create an empty Counter object named log_count to store the number of log
messages.
 Step 4: Open the [Link] file in read mode.
 Step 5: Read the log file one line at a time.
 Step 6: Check whether the current line contains INFO, WARNING, ERROR, or
CRITICAL.
 Step 7: Increase the count of the matching log level by one.
 Step 8: Repeat the checking process until all lines in the file are read.
 Step 9: Display the heading 'Log Summary'.
 Step 10: Print every log level and its total count.
 Step 11: Stop the program.

4. Flow Diagram
The following flow diagram shows how the program reads each line, identifies the log level,
updates the count, and finally displays the summary.

5.

Main Code
from collections import Counter

log_count = Counter()
with open("[Link]", "r") as file:
for line in file:
if "INFO" in line:
log_count["INFO"] += 1
elif "WARNING" in line:
log_count["WARNING"] += 1
elif "ERROR" in line:
log_count["ERROR"] += 1
elif "CRITICAL" in line:
log_count["CRITICAL"] += 1

print("Log Analyse")
for level, count in log_count.items():
print(f"{level}: {count}")

6. Output

Log Analyse
INFO: 4
WARNING: 2
ERROR: 2
CRITICAL: 1

7. Explanation
 The program uses the Counter class to store and count different log levels easily.
 It opens the [Link] file and reads each log entry one by one.
 Each line is checked for INFO, WARNING, ERROR, or CRITICAL using if-elif
conditions.
 When a log level is found, its count is increased by one.
 Finally, the program displays the total count of each log level as a simple log summary.
 This helps users quickly identify normal activities, warnings, errors, and serious system
issues.

PROBLEM STATEMENT -II


DATA REPORT GENERATOR
1. Problem Statement
Organizations and applications generate large amounts of data that can be difficult to understand
in raw form. The Data Report Generator is designed to read and process data, calculate
important values, and produce a clear summary report. This reduces manual work, saves time,
and helps users quickly understand and analyze the available information.

2. Algorithm
 Step 1: Start the program.
 Step 2: Load the 'pandas' data analysis toolkit.
 Step 3: Read the data from '[Link]' and store it in a virtual table (called a
DataFrame).
 Step 4: Print a welcome header '===== DATA REPORT ====='.
 Step 5: Calculate and print the total number of rows and columns.
 Step 6: Extract and print the names of all columns.
 Step 7: Identify and print the data type of each column (e.g., text, decimal numbers).
 Step 8: Count and print the number of missing (blank) values in each column.
 Step 9: Calculate and print mathematical summaries (like average, min, max) for numeric
columns.
 Step 10: Count and print how many unique, distinct values exist in each column.
 Step 11: End the program.

3. Main Code
import pandas as pd

df = pd.read_csv('[Link]')

print(' DATA REPORT ')

print('Rows :', [Link][0])


print('Columns :', [Link][1])

print('\nColumn Names')
print([Link])
print('\nData Types')
print([Link])

print('\nMissing Values')
print([Link]().sum())

print('\nStatistics')
print([Link]())

print('\nUnique Values')
print([Link]())

4. FLOW DIAGRAM

The following flow diagram


shows how the program
reads each line, identifies the
log level, updates the count, and
finally displays the
summary.
Output

DATA REPORT
Rows : 6
Columns : 4

Column Names
Index(['Name', 'Age', 'Department', 'Salary'], dtype='object')

Data Types
Name object
Age float64
Department object
Salary float64
dtype: object

Missing Values
Name 0
Age 1
Department 0
Salary 1
dtype: int64

Statistics
Age Salary
count 5.000000 5.000000
mean 27.600000 46000.000000
std 2.073644 5873.670062
min 25.000000 40000.000000
25% 26.000000 42000.000000
50% 28.000000 45000.000000
75% 29.000000 48000.000000
max 30.000000 55000.000000

Unique Values
Name 6
Age 5
Department 3
Salary 5
dtype: int64
5. Code Explanation (Humanized)
 The pandas library is used to read the [Link] file and organize the employee data
into a DataFrame.
 [Link] displays the total number of rows and columns in the dataset.
 [Link] shows all column names, while [Link] identifies the type of data stored in
each column.
 [Link]().sum() checks the dataset and counts missing values in every column.
 [Link]() calculates basic statistical information such as count, average, minimum,
and maximum values. [Link]() finds the number of unique values available in each
column.
 This program makes employee data analysis easier and generates a clear summary of the
dataset.
PROBLEM STATEMENT -III

BANK ACCOUNT SYSTEM

1. Problem Statement
In everyday life, a bank account must safely keep track of a user's money. We need a system that
allows a user to deposit funds, withdraw funds, and check their current balance. Crucially, the
system must act as a safeguard to prevent overdrafts—meaning it should block a user from
withdrawing more money than they actually have in their account.

2. Algorithm
 Step 1: Start the program.
 Step 2: Define a blueprint (Class) named 'BankAccount'.
 Step 3: Initialize the account with a user's 'name' and a starting 'balance'.
 Step 4: Define a 'deposit' action: Add the deposited amount to the current balance and
display a success message.
 Step 5: Define a 'withdraw' action: Check IF the requested withdrawal amount is less than
or equal to the current balance.
 Step 6: IF True (sufficient funds): Subtract the amount from the balance and display a
success message.
 Step 7: IF False (insufficient funds): Reject the withdrawal and print 'Insufficient
Balance!'.
 Step 8: Define a 'check_balance' action to print the current balance.
 Step 9: Create a new account for 'Ravi' with a starting balance of ₹5000.
 Step 10: Call 'check_balance' (Balance is ₹5000).
 Step 11: Call 'deposit' with ₹2000 (Balance becomes ₹7000).
 Step 12: Call 'withdraw' with ₹3000 (Balance becomes ₹4000).
 Step 13: Call 'withdraw' with ₹7000 (Request fails due to insufficient balance).
 Step 14: Call 'check_balance' (Final Balance is ₹4000).
 Step 15: End the program.

3. Flow Diagram
Below is an editable text-based flowchart representing the withdrawal logic, which is the core
decision-making part of the system. You can modify this directly in Word.
4. MAIN CODE

class BankAccount:

def __init__(self, name, balance):


[Link] = name
[Link] = balance

def deposit(self, amount):


[Link] += amount
print(f'₹{amount} Deposited Successfully')

def withdraw(self, amount):


if amount <= [Link]:
[Link] -= amount
print(f'₹{amount} Withdrawn Successfully')
else:
print('Insufficient Balance!')

def check_balance(self):
print('Current Balance :', [Link])

account = BankAccount('Ravi', 5000)


account.check_balance()
[Link](2000)
[Link](3000)
[Link](7000)
account.check_balance()
5. Expected Output
Current Balance : 5000
₹2000 Deposited Successfully
₹3000 Withdrawn Successfully
Insufficient Balance!
Current Balance : 4000

6. Code Explanation (Humanized)


 The program represents a simple Bank Account Management System for a customer
named Ravi.

 The __init__ method creates Ravi's account with an initial balance of ₹5000.

 The check_balance() method displays the current available account balance.

 The deposit() method adds ₹2000 to the account, increasing the balance from ₹5000 to
₹7000.

 The withdraw() method checks whether enough money is available before completing a
withdrawal.

 Ravi successfully withdraws ₹3000, reducing the balance to ₹4000.

 When Ravi tries to withdraw ₹7000, the program detects insufficient funds and rejects
the transaction.

 Finally, the system displays the remaining balance of ₹4000.

 This program demonstrates class creation, object initialization, methods, conditions,


and basic banking operations in Python.

You might also like