0% found this document useful (0 votes)
2 views5 pages

AI Using Python Exercise 01 Solution

Assignment help the student for course learning

Uploaded by

JAJ Ahmed
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)
2 views5 pages

AI Using Python Exercise 01 Solution

Assignment help the student for course learning

Uploaded by

JAJ Ahmed
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

Hands-on Exercise No.

1 Total Marks: 10
DigiSkills 3.0 Batch-03 AI
Using Python Due Date: 30/04/2026

Instructions:
Please read the following instructions carefully before submitting this Hands-on Exercise:
• Use MS Word to prepare exercise solution.
• You may consult tutorials and videos if the concept is not clear.
• Your submitted exercise will not be considered/counted if:
▪ It is submitted after due date.
▪  It is not in the required format (.doc
or .docx)▪  It does not open, or file is corrupt.
▪ It is copied (partial or full) from any source (websites, forums, students, etc.)

Learning Outcome:

After completing this exercise, you shall be able to:

• Apply conditional statements in Python to solve real-world problems such as tax calculation
based on different conditions.
• Work with lists and dictionaries to transform data and map values (e.g., creating key-value pairs
from a list).
• Understand and implement basic Object-Oriented Programming (OOP) concepts by designing
classes and building a simple chat system with multiple functionalities.
Problem Statement

In this hands-on-exercise, you are required to apply your understanding of basic Python programming,
data structures, and Object-Oriented Programming (OOP) to solve practical problems. You will write
programs using conditional statements for calculations, work with lists and dictionaries to transform data,
and design a simple chat system using classes.
The objective is to strengthen your problem-solving skills and understand how different programming
concepts are applied together to build real-world applications.

You can use any programming environment such as Jupyter Notebook, Google Colab, VS Code, or any
other Python editor to write and execute your programs.

After completing each of the following given task, take screenshots of your code and its output, and paste
them into a single MS Word (.doc/.docx) file as your final solution submission.

Tasks:

1. Write a program that takes salary as input. Using conditional statements, calculate the final tax
based on the following rules: (Marks 3)
• If the salary is less than 30,000→ Tax rate is 5%
• If the salary is between 30,000 and 70,000→ Tax rate is 15%
• If the salary is greater than 70,000→ Tax rate is 25%

SOLUATION
# Input salary
salary = float(input("Enter your salary: "))

# Calculate tax
if salary < 30000:
tax = salary * 0.05
elif salary >= 30000 and salary <= 70000:
tax = salary * 0.15
else:
tax = salary * 0.25

# Final output
print("Salary:", salary)
print("Tax:", tax)
print("Final Salary after Tax:", salary - tax)
2. Given a list of words: words = ["apple", "banana", "kiwi", "cherry", "mango"] (Marks 3)
Create a dictionary that maps each word to its corresponding length.
Example Output: ({"apple": 5, "banana": 6, "kiwi": 4, "cherry": 6, "mango": 5})

SOLUATION

words = ["apple", "banana", "kiwi", "cherry", "mango"]

word_length = {word: len(word) for word in words}

print(word_length)

3. Create a Chat System using Object-Oriented Programming (OOP) concepts. (Marks 4)


You need to create the following classes:
• User
• Message
• ChatRoom
The system should implement the following functionalities:
• Sending messages
• Viewing chat history
• User joining and leaving the chat room

SOLUATION

class User:
def __init__(self, name):
[Link] = name

def send_message(self, chatroom, text):


message = Message([Link], text)
chatroom.add_message(message)

class Message:
def __init__(self, sender, text):
[Link] = sender
[Link] = text

def display(self):
return f"{[Link]}: {[Link]}"

class ChatRoom:
def __init__(self, room_name):
self.room_name = room_name
[Link] = []
[Link] = []

def join(self, user):


[Link](user)
print(f"{[Link]} joined the chat room.")

def leave(self, user):


[Link](user)
print(f"{[Link]} left the chat room.")

def add_message(self, message):


[Link](message)

def show_history(self):
print("\nChat History:")
for message in [Link]:
print([Link]())

# Example Usage
chatroom = ChatRoom("General")

user1 = User("Ali")
user2 = User("Sara")

[Link](user1)
[Link](user2)

user1.send_message(chatroom, "Hello everyone!")


user2.send_message(chatroom, "Hi Ali!")

chatroom.show_history()

[Link](user2)

NOTE: Save the code file at your end and only provide Screenshots of each step in MS Word File.

BEST OF LUCK☺
How to submit solution file on LMS?

Please perform the following steps for submitting your solution using LMS:

1) Login to the LMS

2) Click on the Exercises button within the My Activities section

3) Click on the submit button to upload your Solution.

4) Keep in mind to upload your Solution in .doc or .docx format

You might also like