1. Write a Python program to add 'ing' at the end of a given string (length should be at least 3). If the given string already ends with 'ing', add 'ly' instead. If the string length of the given string is less than 3, leave it unchanged. Ans: def modify_string(s): if len(s) < 3: return s elif s.endswith('ing'): return s + 'ly' else: return s + 'ing' # Get a string from the user user_input = input("Enter a word: ") # Call the function and display the result result = modify_string(user_input) print("Modified word:", result) 2. Write a Python function that takes a list of words and return the longest word and the length of the longest one. Ans: def find_longest_word(words): if not words: # Check if the list is empty return None, 0 longest_word = "" max_length = 0 for word in words: if len(word) > max_length: longest_word = word max_length = len(word) return longest_word, max_length # Example usage: word_list = ["apple", "banana", "cherry", "blueberry", "grape"] longest_word, length = find_longest_word(word_list) print("Longest word:", longest_word) print("Length of the longest word:", length) 3. Write a Python program to pack consecutive duplicates of a given list of elements into sublists. def pack_duplicates(lst): packed_list = [] if not lst: # Check if the list is empty return packed_list current_group = [lst[0]] for i in range(1, len(lst)): if lst[i] == lst[i - 1]: current_group.append(lst[i]) else: packed_list.append(current_group) current_group = [lst[i]] packed_list.append(current_group) return packed_list # Example usage: input_list = [1, 1, 2, 2, 3, 4, 4, 5, 5, 5] result = pack_duplicates(input_list) print("Original List:", input_list) print("Packed Duplicates:", result) 4. Write a Python program to find the item with the most occurrences in a given list. Ans: def most_common_item(lst): if not lst: # Check if the list is empty return None most_common = max(set(lst), key=lst.count) occurrences = lst.count(most_common) return most_common, occurrences # Example usage: input_list = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4] result_item, result_occurrences = most_common_item(input_list) print("Original List:", input_list) print("Most Common Item:", result_item) print("Number of Occurrences:", result_occurrences) 5. Write a Python program to find the highest 3 values of corresponding keys in a dictionary. def highest_values(dictionary): sorted_items = sorted(dictionary.items(), key=lambda x: x[1], reverse=True) top_3_values = sorted_items[:3] return top_3_values # Example usage: input_dict = {'a': 10, 'b': 30, 'c': 20, 'd': 25, 'e': 15} result = highest_values(input_dict) print("Original Dictionary:", input_dict) print("Highest 3 Values:", result) 6. Write a Python program to get the top three items in a shop. Sample data: {'item1': 45.50, 'item2':35, 'item3': 41.30, 'item4':55, 'item5': 24} Expected Output: item4 55 item1 45.5 item3 41.3 def top_three_items(shop_data): sorted_items = sorted(shop_data.items(), key=lambda x: x[1], reverse=True) top_three = sorted_items[:3] return top_three # Sample data shop_data = {'item1': 45.50, 'item2': 35, 'item3': 41.30, 'item4': 55, 'item5': 24} # Get the top three items result = top_three_items(shop_data) # Print the expected output print("Top Three Items:") for item, price in result: print(f"{item} {price}")