Last active
November 22, 2021 18:47
-
-
Save Pratik-Shukla-22/9b56e0b996555ea5a5a6e4b7bdf6ee58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Python program to find the length of an array | |
def find_len(arr): | |
#Initialize the counter with 0 | |
count = 0 | |
#Run a for loop to go through all the elements of the array | |
for element in arr: | |
#For each element in array increase the counter by 1 | |
count = count + 1 | |
#Return the value of counter after exiting the for loop | |
return count | |
#Function Call: | |
arr = [1,2,3,4,5] | |
answer = find_len(arr) | |
print(f"The length of array {arr} is {answer}.") | |
###################### Output ###################### | |
#The length of array [1, 2, 3, 4, 5] is 5. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment