Please solve everything using Python 3
1.Given the following line of code, what is the value of the expression nums.index(20)?
nums = [30, 80, 40, 80, 20, 20, 70, 30, 80]
a. 2
b. 3
c. 4
d. 5
2. Given the following line of code, what is the value of the expression nums.count(80)?
nums = [30, 80, 40, 80, 20, 20, 70, 30, 80]
a. 1
b. 2
c. 3
d. 4
3. Given the following line of code, what is the value of the expression nums.index(80, 2)?
nums = [30, 80, 40, 80, 20, 20, 70, 30, 80]
a. 1
b. 2
c. 3
d. 4
nums = [30, 80, 40, 80, 20, 20, 70, 30, 80]
print(nums.index(20))
print(nums.count(80))
print(nums.index(80, 2))
#output
4
3
3
1) c- 4
reason : index functions searches and returns first occurring instance of given value. first occurrence of 20 is index 4
2) c - 3
reason : count function counts the occurrences of given number. count of 80 is 3
3) c - 3
reason : index( 80,2) starts the search from 2 index and search for element 80. since 80 occurs at index 3 if search begins from 2 index hence 3 is returned.
Get Answers For Free
Most questions answered within 1 hours.