#----------------------------- 1 - Finding largest element in array (function) -------
def largest(arrays, n):
# Initialize maximum element
max = arr[0] # assuming 1st element is larger
# Traverse array elements
for i in range(1, n):
if arr[i] > max: # and compare every element with current element
max = arr[i] # current max
return max
array = []
ele = int(input("Enter the no. of elements : ")) # total no. of elements in the list length of list
# getting inputs from user
print()
for i in range(ele):
print(i+1,end=".")
nums = int(input("Enter the number : "))
array.append(nums)
n = len(array)
maxi = largest(array, n)
print("Largest in given array ", maxi)
#----------------------------- 2 - Finding largest element in array ------------------
array = [] # initializing an empty array
ele = int(input("Enter the no. of elements : ")) # total no. of elements in the list length of list
# getting inputs from user
print()
for i in range(ele):
print(i+1,end=".")
nums = int(input("Enter the number : "))
array.append(nums)
max = array[0]
n = len(array)
for i in range(1, n):
if array[i] > max: # and compare every element with current element
max = array[i] # current max
print("Largest element is : ",max)
#----------------------------- 3 - Sum of elements in array ------------------------------
def Array_sum(array):
# initialize a variable to store the sum
sum = 0
# iterate through the array and add each element
for i in array:
sum = sum + i
return(sum)
array = []
ele = int(input("Enter the no. of elements : ")) # total no. of elements in the list length of list
# getting inputs from user
print()
for i in range(ele):
print(i+1,end=".")
nums = int(input("Enter the number : "))
array.append(nums)
sum = Array_sum(array) # calling the function
print("The sum all elements in given array is : ",sum)
#----------------------------- 4 - Adding key with an array --------------------------
array = []
ele = int(input("Enter the no. of elements : ")) # total no. of elements in the list length of list
# getting inputs from user
print()
for i in range(ele):
print(i+1,end=".")
nums = int(input("Enter the number : "))
array.append(nums)
# printing original list
print("\nThe original list is : ",str(array))
# initializing K
key = int(input("\nEnter the key : "))
# using list comprehension adding key to each element
result = [i + key for i in array]
print("\nAdding.......")
# printing result
print("\nThe array after encrypting each element : " , str(result))