0

Why is question 3 in List Operations 7?

It doesn't make any sense! Why is it 7?!

18th Jan 2017, 8:33 PM
TheMagicalNoodle
TheMagicalNoodle - avatar
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
15th Feb 2019, 3:52 PM
Mayur Patel
Mayur Patel - avatar
+ 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])
18th Jan 2017, 8:47 PM
Andreas K
Andreas K - avatar
0
the answer is 7
17th Dec 2019, 9:30 AM
Jolanta Locmele
Jolanta Locmele - avatar
0
Answer is 7
28th Jan 2020, 5:22 PM
Mike My
Mike My - avatar
0
7
7th Jun 2020, 3:10 PM
Bianca Chinonso
Bianca Chinonso - avatar
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
12th Mar 2021, 5:32 PM
Syed Fahad Ahmed
Syed Fahad Ahmed - avatar
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
10th Oct 2021, 8:15 AM
Pratap Vasava
Pratap Vasava - avatar
0
7
9th Nov 2021, 6:12 AM
lulwa ali
0
7
9th Nov 2022, 5:54 AM
kinzang namgay
kinzang namgay - avatar