0% found this document useful (0 votes)
9 views2 pages

Q-10 Exam Style Python

Uploaded by

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

Q-10 Exam Style Python

Uploaded by

yamaankhan052
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

# Example staff data structure

staff_details = {
"David Doe": {"phone": "123-456-7890", "office": "101A"},
"Bob Smith": {"phone": "234-567-8901", "office": "102B"},
"Alice John": {"phone": "345-678-9012", "office": "101A"},
}

# Display staff phone numbers and names in alphabetical order


def display_staff_alphabetically():
# Sorting staff by name
for name in sorted(staff_details.keys()):
print(f"{name}: {staff_details[name]['phone']}")

# Group members of staff by office number


def group_staff_by_office():
office_groups = {}
# Organizing staff by office
for name, details in staff_details.items():
office = details["office"]
if office not in office_groups:
office_groups[office] = []
office_groups[office].append(name)

# Displaying grouped staff


for office, names in office_groups.items():
print(f"Office {office}: {', '.join(names)}")

# Display all details for a member of staff


def display_staff_details(name):
# Checking if the staff member exists
if name in staff_details:
details = staff_details[name]
print(f"Details for {name}: Phone: {details['phone']}, Office:
{details['office']}")
else:
print(f"Staff member named {name} not found.")

# Update the details for a member of staff


def update_staff_details(name, phone=None, office=None):
# Updating staff details if the staff member exists
if name in staff_details:
if phone:
staff_details[name]['phone'] = phone
if office:
staff_details[name]['office'] = office
print(f"Updated details for {name}.")
else:
print(f"Staff member named {name} not found.")

# Example usage:

# Display staff alphabetically


print("Staff phone numbers and names in alphabetical order:")
display_staff_alphabetically()

print("\nMembers of staff grouped by office number:")


# Group staff by office
group_staff_by_office()
print("\nDisplaying details for a specific staff member:")
# Display details for a specific member
display_staff_details("Bob Smith")

print("\nUpdating details for a specific staff member:")


# Update details for a specific member
update_staff_details("Bob Smith", phone="987-654-3210")

print("\nDisplaying updated details for the same staff member:")


# Display details again to show update
display_staff_details("Bob Smith")

You might also like