0
Why is question 3 in List Operations 7?
It doesn't make any sense! Why is it 7?!
9 Answers
+ 9
nums = [10, 9, 8, 7, 6, 5]
nums[0] = nums[1] - 5
if 4 in nums:
print(nums[3])
else:
print(nums[4])
9-5 == 4 condition is true
so it will print 3rd number of array
[10,9,8,7,6,5]
[0,1,2,3,4,5]
Ans is 7
+ 2
nums = [10, 9, 8, 7, 6, 5]
nums[0] = nums[1] - 5
nums[1] == 9
nums[0] = 9-5 == 4
if 4 in nums:
// this is the case
print(nums[3])
// nums[3] == 7, remember arrays index starts at 0
else:
print(nums[4])
0
the answer is 7
0
Answer is 7
0
7
0
List Operations
What's the result of this code?
nums = [10, 9, 8, 7, 6, 5]
nums[0] = nums[1] - 5
if 4 in nums:
print(nums[3])
else:
print(nums[4])
9-5 == 4 condition is true
so it will print 3rd number of array
[10,9,8,7,6,5]
[0,1,2,3,4,5]
Ans is 7
0
nums = [10, 9, 8, 7, 6, 5]
nums[0] = nums[1] - 5
if 4 in nums:
print(nums[3])
else:
print(nums[4])
answer
nums[0] =nums[1] -5
nums[0]=9-5 =4
replace 10 with new value 4
so we get new list
nums = [4, 9, 8, 7, 6, 5]
if 4 in nums:
print(nums[3]) this condition is true so it will print elemet nums[3]=7
answer=7
0
7
0
7