Professional Documents
Culture Documents
Abhisesha Kumaara
REG NO - RA2211026010487
def find_largest_and_second_largest(arr):
if len(arr) < 2:
second_largest = first_largest
first_largest = num
if second_largest == float('-inf'):
return f"The first largest number is {first_largest} and the second largest number is
{second_largest}"
arr = [12, 34, 56, 23, 67, 45, 90]
result = find_largest_and_second_largest(arr)
print(result)
OUTPUT :
1. Write a Python program to calculate the sum of even numbers and the
sum of odd numbers in an array.
def sum_even_and_odd_numbers(arr):
sum_even = 0
sum_odd = 0
sum_even += num
else:
sum_odd += num
arr = [1, 2, 3, 4, 5, 6, 7, 8]
OUTPUT :
if item == element:
count += 1
return count
arr = [1, 2, 3, 4, 2, 5, 2]
element_to_count = 2
OUTPUT :
def find_palindromic_words(sentence):
words = sentence.split()
palindromic_words = []
if is_palindrome(word):
palindromic_words.append(word)
return palindromic_words
if palindromic_words:
print(word)
else:
OUTPUT :
1. Write a Python program that takes a list of numbers and removes all
duplicates from the list, preserving the original order of elements.
def remove_duplicates(input_list):
unique_list = []
return unique_list
input_list = [1, 2, 2, 3, 4, 4, 5, 6, 6]
result_list = remove_duplicates(input_list)
OUTPUT :
1. Write a Python program that performs matrix multiplication. Ask the
user to input two matrices as lists of lists (2D arrays) and then multiply
them if possible. Make sure to check if the matrices are compatible for
multiplication and handle errors gracefully.
def matrix_multiplication(matrix1, matrix2):
rows1 = len(matrix1)
cols1 = len(matrix1[0])
rows2 = len(matrix2)
cols2 = len(matrix2[0])
if cols1 != rows2:
for i in range(rows1):
for j in range(cols2):
for k in range(cols1):
return result
def input_matrix(prompt):
matrix = []
print(prompt)
while True:
row = input()
if not row:
break
return matrix
try:
matrix1 = input_matrix("Enter the first matrix (each row on a new line, elements
separated by space, and an empty line to finish):")
if result:
except ValueError:
except Exception as e:
OUTPUT :
1. Write a python program to print diamond number pattern using Nested
Loops.
def print_diamond_pattern(n):
print(spaces, end="")
print(j, end="")
print(j, end="")
print()
print()
n=5
print_diamond_pattern(n)
OUTPUT :
def guessing_game():
lower_limit = 1
upper_limit = 100
attempts = 0
try:
attempts += 1
except ValueError:
if __name__ == "__main__":
guessing_game()
OUTPUT :
import string
def check_password_strength(password):
length_criteria = 8
uppercase_criteria = 1
lowercase_criteria = 1
digit_criteria = 1
special_character_criteria = 1
uppercase_count = 0
lowercase_count = 0
digit_count = 0
special_character_count = 0
special_characters = string.punctuation
if char.isupper():
uppercase_count += 1
elif char.islower():
lowercase_count += 1
elif char.isdigit():
digit_count += 1
special_character_count += 1
evaluation = []
if len(evaluation) == 0:
else:
strength_evaluation = check_password_strength(password)
print(strength_evaluation)
OUTPUT :
if n <= 0:
return []
fibonacci_sequence = [0, 1]
while len(fibonacci_sequence) < n:
return fibonacci_sequence
fib_sequence = generate_fibonacci_sequence(num_terms)
if fib_sequence:
print("Fibonacci sequence:")
print(fib_sequence)
else:
OUTPUT :