Need solution (python) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Need solution (python)

Check whether the value of each index matches the value of the element at that index. If Yes, print True If No, print False For example, the arrays [0,1,2,3] and [0,1,2,3,4,5,6] are True, and the array [0,2,2,3,4,5] is False, because the second element in the array is 2 which is different from the parity of the index 1.

15th Dec 2022, 4:22 AM
Zoey
Zoey - avatar
11 Answers
0
#I hope this script can help you #Keep Coding!! lis = [ ] num_el=input("How many elements in list ? : ") for n_times in range(int(num_el)): el=int(input("Give me your Number : ")) lis.append(el) for ind,elms in enumerate(lis): if ind == elms: print(True) else : print(False)
16th Dec 2022, 6:35 AM
myAdminF
myAdminF - avatar
+ 4
What have you tried so far? Hint: you can test if a number is even, with modulo operator number % 2 == 0
15th Dec 2022, 4:29 AM
Tibor Santa
Tibor Santa - avatar
+ 3
Zoey Pls edit your question description and add a link to your code in Code Playground and an explanation of your difficulties. Otherwise, we don't know what help you need.
15th Dec 2022, 11:52 PM
Emerson Prado
Emerson Prado - avatar
+ 1
Do you understand the word "parity"? It means divisible by 2.
15th Dec 2022, 5:08 AM
Tibor Santa
Tibor Santa - avatar
+ 1
myAdminF Pls don't give finished code as answer, because it makes the OP to skip the most important part of learning process. Always prefer giving hints for the OP to find the solution.
16th Dec 2022, 8:38 AM
Emerson Prado
Emerson Prado - avatar
+ 1
Use list.count(item) to see how many times a number appears
16th Dec 2022, 6:02 PM
Kyle Clemmer
Kyle Clemmer - avatar
16th Dec 2022, 11:10 PM
Emerson Prado
Emerson Prado - avatar
0
Tibor Santa Why I need to test is the number is even or not? Example [1,2,3] This is False because the first index of an array is probably 0, but the element in the first index is 1 so there are different.
15th Dec 2022, 4:49 AM
Zoey
Zoey - avatar
0
Tibor Santa Sorry, it is a typo. I have edited it.
15th Dec 2022, 5:13 AM
Zoey
Zoey - avatar
0
Henry M Cloud See my answer to myAdminF
16th Dec 2022, 5:06 PM
Emerson Prado
Emerson Prado - avatar
0
Use a function "all".
17th Dec 2022, 6:52 AM
Вадим Сухотин (Vadim Sukhotin)
Вадим Сухотин (Vadim Sukhotin) - avatar