Python Codes
Python Codes
if discriminant > 0:
elif discriminant == 0:
root = -b / (2 * a)
return root,
else:
# Complex roots
print("Roots:", roots)
def create_pyramid(height):
def create_reverse_pyramid(height):
print("Pyramid:")
create_pyramid(height)
print("\nReverse Pyramid:")
create_reverse_pyramid(height)
if char.isalpha():
if char.isupper():
elif char.islower():
else:
if char.isdigit():
else:
frequency = string.count(char)
return frequency
return new_string
index = string.find(char)
if index != -1:
return new_string
else:
return string
return new_string
string_after_remove_first = remove_first_occurrence(char_to_remove_first,
input_string)
string_after_remove_all = remove_all_occurrences(char_to_remove_all,
input_string)
else:
return "Invalid input: 'n' is greater than the length of one or both strings."
if isinstance(result, tuple):
else:
print(result)
7. WAP to create a list of the cubes of only the even integers appearing in the
input list (may have elements of other types also) using the ’for’ loop
def cube_of_even_integers(input_list):
result_list = []
result_list.append(element**3)
return result_list
# Accept a list from the user (may have elements of other types)
result = cube_of_even_integers(input_list)
def validate_name(name):
try:
validate_name(user_name)
except ValueError as e:
print("Error:", e)