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

Home Assignment.

The document outlines various programming tasks involving conditional statements, loops, and data handling using Python. It includes exercises for user input, calculations (like area, perimeter, and loan eligibility), string manipulation, and data analysis with NumPy arrays. The tasks range from basic programming challenges to more complex data management scenarios, suitable for enhancing programming skills.

Uploaded by

vedant.rok17
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 views11 pages

Home Assignment.

The document outlines various programming tasks involving conditional statements, loops, and data handling using Python. It includes exercises for user input, calculations (like area, perimeter, and loan eligibility), string manipulation, and data analysis with NumPy arrays. The tasks range from basic programming challenges to more complex data management scenarios, suitable for enhancing programming skills.

Uploaded by

vedant.rok17
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

CONDITIONAL STATEMENTS.

●​ Take two inputs from the user and tell which number is greater.

●​ Find the area and perimeter of a rectangle and find for the same dimension is perimeter
greater or area greater.

●​ Write a program to check whether a given year is a leap year. If the year is divisible by 4
but not by 100, or if it is divisible by 400, classify it as a leap year. Additionally,
distinguish between "Century Leap Year" (divisible by 400) and "Common Leap Year"
(divisible by 4 but not by 100). If the year is not a leap year, print "Not a Leap Year.

●​ Take an input from the user and give output its square root & that too only when the
entered number is a perfect square , else give output as ,”Please enter a valid number.”

●​ Enter two numbers , if the second number is greater , then swap the number & then
divide.

●​ Write a program to check loan eligibility based on user input. Take the user's age,
income, and credit score as inputs. Apply the following conditions: if the age is 21 or
older and the credit score is 700 or higher, display "Eligible for all loans." If the credit
score is below 700 but the income is greater than ₹50,000, display "Eligible for small
loans only." Otherwise, display "Not eligible for loans."

●​ Ask the user if their height is in feet (ft) or meters (m) and if their weight is in pounds
(lbs) or kilograms (kg).
-​ Convert the inputs as needed:
●​ If weight is in pounds, convert it to kilograms (1 pound = 0.453592
kg).
●​ If height is in feet, convert it to meters (1 foot = 0.3048 meters).
-​ Validate the inputs to ensure the weight and height values are within a
logical range.
-​ Calculate BMI.
-​ Provide health advice based on the calculated BMI:
-​ BMI < 18.5: Suggest "Underweight – Consult a nutritionist."
-​ 18.5 ≤ BMI < 25: Suggest "Normal weight – Keep it up!"
-​ 25 ≤ BMI < 30: Suggest "Overweight – Consider regular exercise."
-​ BMI ≥ 30: Suggest "Obese – Seek medical advice."

Ensure the program handles invalid inputs gracefully and gives the user clear prompts for
corrections.

●​ Design a program to calculate a shopping bill after applying discounts. Take the total bill
amount and the user's membership status (True/False) as input. Apply a 20% discount if
the bill exceeds ₹10,000, a 10% discount for bills between ₹5,000 and ₹10,000, and no
discount otherwise. If the user is a member, provide an additional 5% discount on the
total amount after applying the initial discount. Display the final amount payable.

●​ Write a program that takes the lengths of three sides of a triangle as input and
determines the type of triangle: equilateral (all sides equal), isosceles (two sides equal),
or scalene (all sides different). If the input values do not form a valid triangle (sum of any
two sides is not greater than the third side), display "Invalid triangle.

●​ Write a program to solve a quadratic equation of the form ax^2 + bx + c = 0. Take the
coefficients a, b, and c as input and calculate the discriminant. Based on the
discriminant, determine whether the equation has real and distinct roots, real and equal
roots, or imaginary roots. Display the roots or an appropriate message for imaginary
roots.

LOOPS.

●​ Find the sum of the series (5+6),(7+7),(9+8), …… 10 terms.​

●​ Print the series 3,33, 333, 3333, 33333, 333333…. Till n terms.​

●​ Write a program to count the occurrences of each character in a string without using any
external libraries or the Counter class.​

●​ Write a program to simulate the "FizzBuzz" problem, but with an additional condition: If a
number is divisible by 7, print "Jazz." If divisible by 3, 5, and 7, print "FizzBuzzJazz.​

●​ Print the Pattern​


654321​
54321​
4321​
321​
21​
1​

●​ Print the pattern


123456​
12345​
1234​
123​
12​
1

●​ Print the series.


1​
12​
123​
1234​
12345​
123456

DATATYPES , LOOPS, CONDITIONAL STATEMENTS.

●​ You are provided with a list of dictionaries representing sales data for a company.
Each dictionary contains the following keys: 'Product', 'Region', and
'Sales'.

sales_data = [

{'Product': 'A', 'Region': 'North', 'Sales': 1000},

{'Product': 'B', 'Region': 'East', 'Sales': 800},

{'Product': 'A', 'Region': 'South', 'Sales': 1200},

{'Product': 'C', 'Region': 'North', 'Sales': 500},

Tasks:

a. Write a program to calculate the total sales for each product.

b. Determine which region has the highest sales for Product 'A'.

●​ A company collects customer feedback scores (1–10) after a purchase. The data
is stored in a list:

feedback_scores = [8, 9, 5, 6, 10, 7, 6, 5, 8, 7, 10, 4]


Tasks:

a. Categorize the feedback into three groups: Poor (1–4),


Average (5–7), and Excellent (8–10). Count the number of
feedback in each category.

b. Calculate the average feedback score and determine if it is


greater than 7 (a satisfactory threshold).

●​ Simulate an ATM withdrawal system:​


a. Take the total amount available in the ATM (e.g., ₹10,000).​
b. Ask the user for the amount they want to withdraw.​
c. Ensure the amount is divisible by 100, is less than the available balance, and
does not exceed ₹5,000 per transaction.​
d. Update the available balance and allow withdrawals until the ATM runs out of
money.

●​ Write a program to calculate the frequency of each character in a given string


(ignoring spaces).

●​ Write a program that takes integer input from the user and counts in the output
shows the number of digits and sum of the digits.​
Eg - I/P- 5432​
O/P - count - 4 , sum - 14

●​ Given a list of numbers, find the largest , smallest number in the list and find
their indices (positions ) in the list.

●​ Write a program to validate a password based on these rules:​


- Passwords should be at least 8 characters long. ​
- First word of the password should be any number between 1 and 9​
- Contains at least one special character (@, # , $, % , &)
●​ Write a Python program that takes a string as input and counts the number of
vowels and consonants in it.

●​ Design a dynamic inventory management system for a retail store. The system
should allow the user to perform the following tasks:
■​ Add new products to the inventory.
■​ Update the stock levels of existing products.
■​ Check the availability of a specific product.
■​ Generate a summary report of the inventory, including products with
stock levels below a specified threshold.

NUMPY

1- Given a 2D array representing student marks in 5 subjects and each row representing a
student, find the student with the highest total marks.​
marks = [Link]([[85, 90, 78, 92, 88], [76, 81, 85, 80, 79], [90, 88, 91, 92, 89], [70, 75, 65, 60,
68]])

2- From a customer purchase dataset, categorize customers into "High Spend" (spend > 1500)
and "Low Spend" (spend <= 1500).​
purchases = [Link]([[1, 1200], [2, 850], [3, 2000], [4, 1300], [5, 1800]])

3- Group transactions by item_id and calculate the total quantity_sold and


sales_amount for each item.​
transactions = [Link]([[101, 5, 100], [102, 3, 75], [101, 2, 40], [103, 1, 20], [102, 4, 100]])

4- You are given a 2D NumPy array where each row represents a customer and the columns
represent their interaction metrics:

●​ Column 1: Total purchases in the last year


●​ Column 2: Average time spent on the website per visit (in minutes)
●​ Column 3: Total complaints lodged
●​ Column 4: Average customer rating given (out of 5)

data = [Link]([[12, 5.2, 1, 4.5], [8, 3.5, 3, 2.2], [15, 7.8, 0, 5], [6, 4.1, 5, 1.8], [10, 6.0, 0,
3.2], [5, 2.5, 6, 1.1]])

Tasks:

●​ Identify the customers who are at the risk of churn (Churn risk , if purchase is less than
average purchase, Their complaints are greater than 2, or their average customer rating
is below 2.5.
●​ Calculate the percentage of customers at risk.
●​ Sort these at-risk customers in descending order of complaints lodged.

5- You are provided with a 2D NumPy array where each row contains data about a store's
revenue:

●​ Column 1: Store ID
●​ Column 2: Revenue for the current year
●​ Column 3: Revenue for the previous year
●​ Column 4: Operational costs for the current year

store_data = [Link]([[1, 120000, 150000, 80000], [2, 90000, 100000, 70000], [3,
200000, 250000, 150000], [4, 80000, 75000, 60000]])

Tasks:

1.​ Identify stores with declining profits (profit = revenue - costs) compared to the previous
year.
2.​ For these stores, calculate the percentage decline in profit.
3.​ Rank these stores based on the percentage decline.

6- You have a 2D NumPy array where each row represents a student and the columns
represent:

●​ Column 1: Student ID
●​ Column 2: Score in Math
●​ Column 3: Score in Science
●​ Column 4: Score in English

Tasks:

1.​ Identify students who scored below the average in at least two subjects.
2.​ For these students, calculate their total score.
3.​ Rank these students by their total score in ascending order.

exam_scores = [Link]([[1, 80, 75, 60], [2, 70, 85, 65], [3, 60, 55, 50], [4, 90, 95, 85], [5, 50, 45,
55]])

7- You are given a 2D NumPy array where each row represents a day's power consumption
data for different regions:

●​ Column 1: Region ID
●​ Column 2: Power consumption in kWh during peak hours
●​ Column 3: Power consumption in kWh during non-peak hours
●​ Column 4: Total cost of power consumption (in dollars)

power_data = [Link]([[1, 120, 50, 300], [2, 150, 70, 400], [3, 200, 90, 500], [4, 90, 45, 250], [5,
100, 80, 200]])

Tasks:

1.​ Find regions where power consumption during peak hours is more than twice that of
non-peak hours.
2.​ For these regions, calculate the cost-to-consumption ratio (cost per kWh).
3.​ Identify the region with the highest cost-to-consumption ratio.

8- You have a 2D NumPy array where each row represents an employee:

●​ Column 1: Employee ID
●​ Column 2: Current salary
●​ Column 3: Years of experience
●​ Column 4: Performance rating (out of 10)​
employee_data = [Link]([[1, 50000, 6, 9], [2, 60000, 3, 7], [3, 55000, 8, 8.5], [4, 45000,
2, 5], [5, 70000, 7, 8]])

Tasks:

1.​ Identify employees who are eligible for a salary increase based on the following
conditions:
○​ They have at least 5 years of experience, and
○​ They have a performance rating greater than or equal to 8.
2.​ Calculate the new salary for eligible employees by increasing their salary by 10%.

9- A retail company tracks customer spending using the following 2D NumPy array:

●​ Column 1: Customer ID
●​ Column 2: Total purchases in the last 6 months
●​ Column 3: Average purchase frequency (in days)
●​ Column 4: Loyalty points earned​
customer_data = [Link]([[1, 200, 25, 50], [2, 400, 35, 100], [3, 600, 20, 150], [4, 300,
15, 60]])

Tasks:

1.​ Identify customers who:


○​ Made purchases of less than $500 in the last 6 months, and
○​ Have made purchases more frequently than every 30 days.
2.​ Calculate the loyalty points to spending ratio for these customers.

10-You have a dataset of employees with the following attributes:

●​ Column 1: Employee ID
●​ Column 2: Department ID
●​ Column 3: Current Salary
●​ Column 4: Years of Experience
●​ Column 5: Performance Rating (out of 10)
●​ Column 6: Work Location (represented as an integer)​
employee_data = [Link]([[1, 101, 50000, 6, 9, 2], [2, 102, 60000, 4, 8, 1], [3, 103,
70000, 10, 9.5, 2], [4, 104, 80000, 8, 6, 1]])

Tasks:

1.​ Calculate a performance-based compensation adjustment (in percentage) using the


following criteria:
○​ If the employee has a performance rating >= 9, increase salary by 15%.
○​ If the employee has 5-10 years of experience, increase salary by 10%.
○​ If the employee works in a "high cost of living" location (denoted by location code
2), increase salary by 5%.
2.​ Ensure that no employee’s total salary adjustment exceeds 25%.
3.​ Apply the adjustments to the salaries and output the final salary for each employee.
11- You are given sales data for different products:

●​ Column 1: Product ID
●​ Column 2: Sales for Q1
●​ Column 3: Sales for Q2
●​ Column 4: Sales for Q3
●​ Column 5: Sales for Q4​
sales_data = [Link]([[101, 200, 250, 300, 350], [102, 300, 350, 400, 450], [103, 150,
180, 200, 220], [104, 500, 550, 600, 650]])

Tasks:

1.​ Calculate the total yearly sales for each product.


2.​ Identify products that had an increase in sales during Q4 compared to Q3.
3.​ Identify products that had the highest and lowest sales in each quarter.

12- You have sales data for a company where each row represents sales information for a
region. The columns represent region, product type, and sales amount.​
sales_data = [Link]([ ['North', 'Electronics', 1000], ['South', 'Clothing', 1500], ['East',
'Electronics', 2000], ['West', 'Furniture', 500], ['North', 'Clothing', 700], ['South', 'Furniture', 300],
['East', 'Furniture', 800], ['West', 'Clothing', 1200] ])

PANDAS

Spending Patterns Dataset

1.​ How many unique customers are in the dataset?


2.​ Find the average spending for each category.
3.​ Compare spending in "Electronics" vs. "Clothing"
4.​ What is the total number of transactions that occurred in the last 6 months of 2024?
5.​ What is the average spending per transaction for weekends vs. weekdays?
6.​ Identify the month and year with the highest number of transactions.
7.​ What percentage of customers have made purchases in at least 5 different categories?
8.​ Which day of the week sees the highest average transaction value?
9.​ Which category and item combination generated the highest revenue in 2023?
10.​Group spending data by customer and identify the average transaction value for each
customer.
11.​Find customers whose total quantity of purchased items in the "Groceries" category
exceeds 100.
12.​Identify customers with transactions in multiple locations (cross-location spenders).
13.​What percentage of transactions involve a "Credit Card" as the payment method?
14.​Filter transactions for "Housing and Utilities" where the total spent exceeds $500 in a
single transaction.
15.​Which items are purchased the most in "In-store" vs "Mobile App" purchases?
16.​Identify customers who made purchases every month of the year.
17.​What are the most common payment methods used for high-value transactions (>
$1,000)?
18.​Identify the Top 3 Spending Customers for Each Month and year and Their Contribution
to the Monthly Total Revenue.
19.​For each customer, determine their most frequently purchased category (based on the
number of transactions). Then, calculate the percentage of their total transactions that
fall under this category.
20.​Identify customers whose monthly spending remains consistent. Define consistency as
having a coefficient of variation (standard deviation/mean) of monthly spending below
10%.

MELT AND PIVOT

Problem 1: Global Retail Sales and Currency Conversion Analysis


A multinational retailer operates in multiple countries, selling various products. The company's
financial team struggles with analyzing sales performance across different currencies and wants
a standardized analysis in USD. The data is currently in a wide format with sales recorded
separately for each country in local currencies.

data = { "Product_ID": [101, 102, 103, 104], "Product_Name": ["Laptop", "Smartphone", "Tablet",
"Headphones"], "Sales_USD": [50000, 60000, 30000, 15000], "Sales_EUR": [45000, 55000,
32000, 16000], "Sales_GBP": [40000, 52000, 31000, 14000], "Sales_JPY": [5300000, 6400000,
3300000, 1800000], "Exchange_Rate_EUR": [1.1, 1.1, 1.1, 1.1], "Exchange_Rate_GBP": [1.3,
1.3, 1.3, 1.3], "Exchange_Rate_JPY": [0.009, 0.009, 0.009, 0.009], }

Your Task:

●​ Decide how to reshape the data to make sales comparisons easier.


●​ Implement transformations to:
○​ Convert all sales into USD.
○​ Find total revenue per currency.
○​ Determine the best and worst-performing products.
●​ Generate insights based on transformed data.
Problem 2: Employee Work Hours & Productivity Optimization
A consulting firm tracks employee work hours across projects and weekdays. However, the HR
team struggles to analyze productivity trends, overtime issues, and employee workload
distribution.

data = { "Employee_ID": [1, 2, 3, 4], "Name": ["Alice", "Bob", "Charlie", "David"],


"Project_A_Mon": [4, 5, 3, 2], "Project_A_Tue": [6, 7, 2, 3], "Project_B_Mon": [5, 6, 4, 3],
"Project_B_Tue": [3, 5, 6, 4], "Project_C_Wed": [7, 5, 6, 8], "Project_C_Thu": [6, 4, 5, 7], }

Your Task:

●​ Decide how to reshape the data to allow for better workload tracking.
●​ Implement transformations to:
○​ Structure data for per-project, per-day analysis.
○​ Identify overtime cases.
○​ Find the highest workload project.
●​ Generate insights based on transformed data.

You might also like