1.) def print_list_info(my_list): print("Total number of items in the list:", len(my_list)) print("Fourth item in the list:", my_list[3]) print("Last three items in the list:", my_list[-3:]) print("All items in the list except the first two:", my_list[2:]) print("List in reverse order:", my_list[::-1]) print("Largest value in the list:", max(my_list)) print("Smallest value in the list:", min(my_list)) print("Sum of all values in the list:", sum(my_list)) if 0 in my_list: print("Index of the first zero in the list:", my_list.index(0)) else: print("There are no zeroes in the list.") sorted_list = sorted(my_list) print("List after sorting:", sorted_list) sorted_list.pop(0) print("List after deleting the first item:", sorted_list) sorted_list[-2] = 9876 print("List after changing the second-to-last item:", sorted_list) sorted_list.append(-500) print("List after appending -500:", sorted_list) def output_fn(): user_input = input("Enter at least five integers separated by spaces: ") my_list = [int(x) for x in user_input.split()] if len(my_list) >= 5: print_list_info(my_list) else: print("Please enter at least five integers.") output_fn() ################################################################################################################################ 2.) def find_smallest_number_and_index(input_list): smallest_number = min(input_list) index_of_smallest = input_list.index(smallest_number) return smallest_number, index_of_smallest def output_fn(): user_input = input("Enter a list of numbers separated by spaces: ") numbers_list = [float(x) for x in user_input.split()] if len(numbers_list) > 0: smallest_num, index_of_smallest = find_smallest_number_and_index(numbers_list) print("Smallest number in the list:", smallest_num) print("First index at which it appears:", index_of_smallest) else: print("Please enter a valid list of numbers.") output_fn() #################################################################################################################################### 3.) def count_letter_occurrences(input_string): letter_counts = [0] * 26 for char in input_string: if 'a' <= char <= 'z': letter_counts[ord(char) - ord('a')] += 1 return letter_counts def output_fn(): user_input = input("Enter a string of lowercase letters: ") letter_counts = count_letter_occurrences(user_input) # Print the letter counts. for i in range(26): letter = chr(i + ord('a')) count = letter_counts[i] print(f"Number of '{letter}'s in the string: {count}") output_fn() #################################################################################################################################### def output(): my_dict = { 'abc': 7, 'def': 11, 'ghi': 13, 'jkl': 17, 'mno': 19 } print("Value associated with 'def':", my_dict['def']) print("All keys in the dictionary:", list(my_dict.keys())) print("Keys and their associated values:") for key, value in my_dict.items(): print(f"{key}: {value}") if 'pqr' in my_dict: print("The dictionary contains the key 'pqr'.") else: print("The dictionary does not contain the key 'pqr'.") my_dict['abc'] = 23 print("All values in the dictionary:", list(my_dict.values())) output()