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.
11 Antworten
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)
+ 4
What have you tried so far?
Hint: you can test if a number is even, with modulo operator
number % 2 == 0
+ 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.
+ 1
Do you understand the word "parity"?
It means divisible by 2.
+ 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.
+ 1
Use list.count(item) to see how many times a number appears
+ 1
Вадим Сухотин (Vadim Sukhotin) See my answer to myAdminF
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.
0
Tibor Santa
Sorry, it is a typo. I have edited it.
0
Henry M Cloud See my answer to myAdminF
0
Use a function "all".