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

Python String and Data Structure Operations

hoahwohd woiahdoi

Uploaded by

deathmangers
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)
2 views8 pages

Python String and Data Structure Operations

hoahwohd woiahdoi

Uploaded by

deathmangers
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

Ex. No.

: 4A
STRING MANIPULATION – EMAIL VERIFICATION AND NAME FORMATTING
Date:

Aim:

To write a Python program to perform string manipulations for verifying and


formatting user details.

Algorithm:

Step 1: Start the program.


Step 2: Input the full name and email address.
Step 3: Remove unwanted spaces using strip().
Step 4: Split the name and extract the first and last names.
Step 5: Check whether the email is valid using '@' in email and endswith('.com').
Step 6: Format the name in title case and display details.
Step 7: Stop the program.

Program:

# Program to manipulate strings and validate email

def validate_email(email):

return '@' in email and [Link]('.com')

name = input("Enter your full name: ").strip()

email = input("Enter your email: ").strip()

first, last = [Link]()[0], [Link]()[-1

print("\n--- USER DETAILS ---")

print("Full Name (Title Case):", [Link]())

print("First Name:", first)

print("Last Name:", last)

print("Email Validity:", "Valid" if validate_email(email) else "Invalid")


Result:

The program successfully performs string manipulation and validates an email


address.
Ex. No.: 4B
LIST OPERATIONS – SHOPPING CART MANAGEMENT
Date:

Aim:

To write a Python program to perform various list operations in a shopping cart.

Algorithm:

Step 1: Start the program.


Step 2: Create a list of shopping items.
Step 3: Add a new item to the cart using append().
Step 4: Remove an unwanted item using remove().
Step 5: Sort the list and count total items.
Step 6: Search for a specific product using the in operator.
Step 7: Display the updated cart.

Program:

# Program to manage a shopping cart using list operations

cart = ["Milk", "Bread", "Eggs", "Butter"]

print("Initial Cart:", cart)

[Link]("Cheese")

[Link]("Bread")

[Link]()

print("\nUpdated Cart:", cart)

print("Total Items:", len(cart)

item = input("Enter item to search: ")

if item in cart:

print(item, "is available in the cart.")

else:

print(item, "is not found.")


Result:

The program successfully performs list operations like adding, removing, sorting, and
searching.
Ex. No.: 4C
TUPLES – STUDENT RECORD DISPLAY SYSTEM
Date:

Aim:

To write a Python program using tuples to store and display student details.

Algorithm:

Step 1: Start the program.


Step 2: Create a tuple containing student details.
Step 3: Access tuple elements using indexing.
Step 4: Display formatted details of the student.
Step 5: Stop the program.

Program:

# Program to store and display student information using tuple

student = ("A1023", "John", "Information Technology", 8.9)

print("--- STUDENT RECORD ---")

print("Register Number:", student[0])

print("Name:", student[1])

print("Department:", student[2])

print("CGPA:", student[3])

if student[3] >= 9:

print("Remark: Excellent")

elif student[3] >= 8:

print("Remark: Very Good")

else:

print("Remark: Good")
Result:

The program successfully stores and displays student details using a tuple.
Ex. No.: 4D
DICTIONARIES – EMPLOYEE PAYROLL SYSTEM
Date:

Aim:

To write a Python program using dictionaries to manage employee salary details.

Algorithm:

Step 1: Start the program.


Step 2: Create a dictionary with employee name as key and salary as value.
Step 3: Add a new employee record.
Step 4: Update an employee’s salary.
Step 5: Remove an employee record.
Step 6: Display all records using a loop.

Program:

# Program to manage employee salary details using dictionary

employees = {"John": 35000, "Mary": 42000, "Peter": 38000}

print("Initial Employee Data:", employees)

employees["David"] = 40000

employees["Mary"] += 2000

del employees["John"

print("\nUpdated Employee Data:")

for name, salary in [Link]():

print(name, "=> ₹", salary)

search = input("\nEnter employee name to check salary: ").title()

print("Salary:", [Link](search, "Employee not found"))


OUTPUT:

Result:

The program successfully performs operations on dictionaries for managing employee


data.

You might also like