Write a small function for iterating over an array of size 4. Check if the value
present at index 3 is a number then function should return true otherwise
false
Answers
Flas) fh krishan eijdhdbcxghzisis
Language used: Python Programming.
In python, lists acts as heterogeneous arrays. So, let us use lists and check whether the element at index 3 is a number or not.
Program:
#Function that checks if the element at index 3 is a number or not.
#Remember that indexing starts with 0. So, index 3 will be the last element position in array of size 4. So, index 3 equals index -1.
def checkIndex(arr):
#checking if element at index 3 is a number or not. If yes, return true
if arr[3].isnumeric():
return 'true'
#If the above condition fails, return false.
return 'false'
#initializing array
arr=[]
#appending 4 elements into array
for i in range(4):
arr.append(input())
#calling the function and printing the returned value
print(checkIndex(arr))
Input:
preethi
govind
ravi
99
Output:
true
Input:
1
arjun
4.32
abhimanyu
Output:
false
Learn more:
Your friend and you made a list of topics and both of them voted if they like or dislike the topic. They wrote 0 to denote dislike and 1 to denote like..
https://brainly.in/question/44681897
Indentation is must in python. Know more about it at:
https://brainly.in/question/1773116