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

Ai&Ml Using Python Lab

The document outlines a Master of Computer Applications course focusing on Artificial Intelligence and Machine Learning using Python for the academic year 2024-2025. It includes case studies on conditional statements for retail discounts, looping structures for donation tracking, data structures for student management, and visualization of monthly sales data using Python libraries. Each section provides a problem statement, program code, and expected output.

Uploaded by

shivagoture133
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)
22 views11 pages

Ai&Ml Using Python Lab

The document outlines a Master of Computer Applications course focusing on Artificial Intelligence and Machine Learning using Python for the academic year 2024-2025. It includes case studies on conditional statements for retail discounts, looping structures for donation tracking, data structures for student management, and visualization of monthly sales data using Python libraries. Each section provides a problem statement, program code, and expected output.

Uploaded by

shivagoture133
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
You are on page 1/ 11

PROGRAM: MASTER OF COMPUTER APPLICATIONS COURSE

NAME: ARTIFICIAL INTELLIGENCE & MACHINE LEARNING


USING PYTHON
CODE: MMC201
ACADEMIC YEAR: 2024-2025
SEMESTER: 2nd SEMESTER
PART
A
1. Conditional Statements – Case Study

Case Study:
A retail store offers discounts based on customer type and purchase amount.
Problem Statement:
Write a Python program that takes customer type (Regular or Premium) and purchase amount as input.

 If the customer is Premium and spends more than ₹5000, apply a 20% discount.
 If Regular and spends more than ₹3000, apply a 10% discount.
 Otherwise, no discount.
 Display the final amount to be paid.

Program:

# Get inputs from the user

customer_type = input("Enter customer type (Regular/Premium): ").strip().capitalize()

purchase_amount = float(input("Enter purchase amount (₹): "))

# Apply conditional logic with if, elif, else

if customer_type == "Premium" and purchase_amount > 5000:

final_amount = purchase_amount * 0.80 # 20% discount

elif customer_type == "Regular" and purchase_amount > 3000:

final_amount = purchase_amount * 0.90 # 10% discount

else:

final_amount = purchase_amount # No discount


PART
A
# Display the final amount

print(f"Final amount to be paid: ₹{final_amount:.2f}")

Output:

Enter customer type (Regular/Premium): Regular

Enter purchase amount (₹): 6500

Final amount to be paid: ₹5850.00

Enter customer type (Regular/Premium): Premium

Enter purchase amount (₹): 3000

Final amount to be paid: ₹3000.00


PART
A
2. Looping Structures – Case Study

Case Study:
An NGO tracks donations collected over 7 days.
Problem Statement:
Write a Python program to input daily donations for a week and use a loop to:

 Calculate the total donation.


 Find the average per day.
 Identify the highest donation day.

Program:

# Input donations using a for loop


donations = []
for day in range(1, 8):
amount = float(input(f"Enter donation for day {day}: ₹"))
donations.append(amount)

# Use while loop to calculate total donation


total_donation = 0
index = 0
while index < len(donations):
total_donation += donations[index]
index += 1

# Calculate average donation


average_donation = total_donation / len(donations)
PART
Aand day
# Use while loop to find highest donation
highest_donation = donations[0]
highest_day = 1
index = 1
while index < len(donations):
if donations[index] > highest_donation:
highest_donation = donations[index]
highest_day = index + 1
index += 1

print(f"\nTotal donation collected: ₹{total_donation:.2f}")


print(f"Average donation per day: ₹{average_donation:.2f}")
print(f"Highest donation was on day {highest_day} with ₹{highest_donation:.2f}")

Output:

Enter donation for day 1: ₹300


Enter donation for day 2: ₹500
Enter donation for day 3: ₹600
Enter donation for day 4: ₹7000
Enter donation for day 5: ₹520
Enter donation for day 6: ₹620
Enter donation for day 7: ₹250

Total donation collected: ₹9790.00


Average donation per day: ₹1398.57
Highest donation was on day 4 with ₹7000.00
PART
A
3. List, Tuple, Set, Dictionary – Case Study

Case Study:
A student management system stores student data using appropriate data structures.
Problem Statement:
Write a Python program to:

 Store names and marks of students using a dictionary.


 Store subjects using a tuple.
 Use a list to maintain student IDs.
 Use a set to keep track of unique courses taken.
 Display student details and ensure no duplicate courses.

Program:

# Input subjects from user, then convert to tuple

subjects_input = input("Enter subjects separated by commas: ")

subjects = tuple(sub.strip() for sub in subjects_input.split(","))

# Input number of students

num_students = int(input("Enter number of students: "))

# Initialize data structures

student_ids = []

students = {}

unique_courses = set()
PART
# Input student details A
for _ in range(num_students):

student_id = int(input("\nEnter student ID: "))

student_ids.append(student_id)

name = input("Enter student name: ")

print(f"Enter marks for {name} (enter -1 if not applicable):")

marks = {}

for subject in subjects:

mark = float(input(f" {subject}: "))

if mark != -1:

marks[subject] = mark

unique_courses.add(subject) # Track unique courses

students[student_id] = {"name": name, "marks": marks}

# Display all student details

print("\n--- Student Details ---")

for student_id in student_ids:

student = students[student_id]

print(f"\nStudent ID: {student_id}")

print(f"Name: {student['name']}")
PART
A
print("Marks:")

for subject in subjects:

score = student['marks'].get(subject, "N/A")

print(f" {subject}: {score}")

# Display unique courses taken

print("\nUnique courses taken by students:")

for course in unique_courses:

print(course)
PART
A
4. Visualization – Case Study

Case Study:
An e-commerce platform wants to visualize monthly sales data.
Problem Statement:
Write a Python program using matplotlib or seaborn to plot:

 A bar chart of monthly sales (Jan–Dec).


 A pie chart showing percentage sales of top 4 products.

A line graph showing the sales trend.

Program:

import matplotlib.pyplot as plt

# Sample data

months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',

'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']

monthly_sales = [1200, 1500, 1700, 1400, 1800, 2000, 2100, 1900, 2200, 2300, 2500, 2700]

products = ['Product A', 'Product B', 'Product C', 'Product D', 'Product E', 'Product F']

product_sales = [5000, 3000, 4000, 3500, 2000, 1500]


PART
# Bar Chart: Monthly Sales A
plt.figure(figsize=(10, 6))

plt.bar(months, monthly_sales, color='skyblue')

plt.title('Monthly Sales (Jan-Dec)')

plt.xlabel('Months')

plt.ylabel('Sales (₹)')

plt.grid(axis='y', linestyle='--', alpha=0.7)

plt.show()

# Pie Chart: Top 4 Product Sales Percentage

top4_products = products[:4]

top4_sales = product_sales[:4]

plt.figure(figsize=(8, 8))

plt.pie(top4_sales, labels=top4_products, autopct='%1.1f%%', startangle=140, colors=['gold',


'lightcoral', 'lightskyblue', 'lightgreen'])

plt.title('Percentage Sales of Top 4 Products')

plt.axis('equal') # Equal aspect ratio ensures pie is circular.

plt.show()
PART
# Line Graph: Sales Trend over Months A
plt.figure(figsize=(10, 6))

plt.plot(months, monthly_sales, marker='o', linestyle='-', color='purple')

plt.title('Sales Trend Over Months')

plt.xlabel('Months')

plt.ylabel('Sales (₹)')

plt.grid(True, linestyle='--', alpha=0.7)

plt.show()

You might also like