Basic Python Programs – 4

#----------------------------- 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))

Join our team, where career growth knows no limits.

For More Details

Our internship program guarantees personalized attention for optimal career development in the tech industry.

+91 97879 68375

-> You should bring your own laptop during the internship

Who can apply?

Internships are open for students who: B.E / B.Tech / M.E / M.Tech / B.Sc / M.Sc / M.C.A / B.C.A / Diploma.

  • Ongoing Students Only
  • days, 5days/ 10days or Based on Student Preference
  • Limited 1 to 10 students per slot
  • Registration fees : 1000 INR
  • Slots are filling quickly only fewer slots are available