Renuka Rai Python Project File
Renuka Rai Python Project File
def count_words(sentence):
words = sentence.split()
return len(words)
# main
input_string = "Hello Everyone! I am Renuka Rai."
word_count = count_words(input_string)
print("Number of words:", word_count)
def max_frequency_char(string):
char_freq = {}
# Count frequencies
for char in string:
char_freq[char] = char_freq.get(char, 0) + 1
return max_freq_char
# main
string = "Phenomenon"
max_char = max_frequency_char(string)
print("The maximum frequency character in the string is:", max_char)
def print_even_numbers(list1):
for num in list1:
if num % 2 == 0:
print(num)
# main
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
print("Even numbers in the list:")
print_even_numbers(numbers)
def remove_last_element(input_tuple):
new_tuple = input_tuple[:-1]
return new_tuple
# main
original_tuple = (1,2,3,4)
print("Original tuple:", original_tuple)
modified_tuple = remove_last_element(original_tuple)
print("Tuple after removing the last element:", modified_tuple)
max_elements = sorted_tuple[-k:]
min_elements = sorted_tuple[:k]
# main
input_tuple = (3, 1, 5, 2, 4,7,8)
k=3
max_elements, min_elements = max_min_k_elements(input_tuple, k)
print("The maximum 3 elements in the tuple are:", max_elements)
print("The minimum 3 elements in the tuple are:", min_elements)
return merged_dict
#main
dict1 = {'Summer': 1, 'Winter': 2}
dict2 = {'Spring': 3, 'Autumn': 4}
#main
my_dict = {'a': 1, 'b': 2, 'c': 3,'d':4}
check_key_exists(my_dict, 'c')
check_key_exists(my_dict, 'j')
#main
my_list = ['apple', 'banana', 'orange', 'grape']
swap_elements(my_list, 0, 3)