Question

Please solve everything using Python 3 1.Given the following line of code, what is the value...

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

Homework Answers

Answer #1

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.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a function reshaped_by_col(nums, col) which takes a Python list nums, and an integer value for...
Write a function reshaped_by_col(nums, col) which takes a Python list nums, and an integer value for columns that reshapes the 1D nums into col number of columns. Finally, returns the reshaped numpy array. If the shape cannot be reshaped, return None (you can do this without catching exceptions). For example: Test Result nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100] col = 2 print(reshaped_by_col(nums, col)) [[ 10 20] [ 30 40] [ 50 60] [ 70...
Solve the following problem in juypter/python code and plot any results. Suppose that the values for...
Solve the following problem in juypter/python code and plot any results. Suppose that the values for a given set of data are grouped into intervals. The intervals and corresponding frequencies are as follows. Age   frequency 1-5      200 5-15    450 15-20 300 20-50   1500 50-80   700 80-110 44 Compute an approximate median value of age for the data? Output your Answer as answer.csv in the output directory:
In python comment the following code line by line as to what each line does def...
In python comment the following code line by line as to what each line does def f(x): return 6*x**5-5*x**4-4*x**3+3*x**2 #here we define a polynomial def df(x): return 30*x**4-20*x**3-12*x**2+6*x #here we define a polynomial that takes the derivative of the above function f(x) def dx(f, x): return abs(0 - f(x)) def newtons_method(f, df, x0, e): delta = dx(f, x0) while delta > e: x0 = x0 - f(x0)/df(x0) delta = dx(f, x0) print('Root is at:', x0) print('f(x) at root is: ',...
Lagrange Interpolation polynomial using python of degree 3 I understand the math for the question I...
Lagrange Interpolation polynomial using python of degree 3 I understand the math for the question I cannot seem to get the correct python code please help with python to solve For f (x) = x ln(x), (1) use appropriate Lagrange interpolating polynomial of degree three to approximate f(8.4). Use the following data: f(8.1) = 16.94410, f(8.3) = 17.56492, f(8.6) = 18.50515, f(8.7) = 18.82091. (2) use appropriate Newton interpolation polynomial again to redo the work. Everything has to be done...
Python: Provide code and result Given 4 values x, y, s, and t. Write a one-line...
Python: Provide code and result Given 4 values x, y, s, and t. Write a one-line command to check if x > y or s > t. If yes, the code should output "True" We try to define a function in Figure 2, please identify two problems with the code. Write an inline if statement to assign x the value 1 if the variable y = 'female' and assign x the value 0 if the variable y = 'male'. The...
1: A) Given the following vectorized code: >>x=[1:10]; >>f=x.^2+2; Rewrite this code using a for loop...
1: A) Given the following vectorized code: >>x=[1:10]; >>f=x.^2+2; Rewrite this code using a for loop that defines each element of f one at a time. Make sure to preallocate memory to f before filling each spot. B) See the following code. Rewrite the code in one line using the find function and a For loop. then write it again using a while loop x=[-1 3 7 2 4 0]; v=[]; for i=1:length(x) if x(i)<=2 v=[v, x(i)]; end end please...
The code segment in Listing 1, when completed and executed, creates nums, an uninitialized 4-integer array....
The code segment in Listing 1, when completed and executed, creates nums, an uninitialized 4-integer array. It stores 4 and 5 as the first and second elements, respectively, of the array. It adds the first and second elements of the array and stores their sum as the third element of the nums. It prints the third element of nums. It then adds the second and third elements of the array and stores their sum as the fourth element of nums....
3. What will be the value of w after the following section of code executes: int...
3. What will be the value of w after the following section of code executes: int w = 4, q = 3; if (q > 5)       if (w == 7)           w == 3;       else            if (w > 3)               w = 1;            else               w = 0; A.0            B.1              C.2          D.3 4. What will be the value of b after the following section of code executes: int a = 4, b = 0; if (a...
Using Euclid's Propositions (book 1, 1-3), solve the following: A) Construct a line segment whose length...
Using Euclid's Propositions (book 1, 1-3), solve the following: A) Construct a line segment whose length is double that of a given line segment. B) At a given point P, construct a line segment whose length is double that of a given line segment AB. C) Construct a line segment whose length is the sum of the lengths of two given line segments AB and CD. D) At a given point P, construct a line segment whose length equals the...
1. What will the following python code display? num = list(range(5)) print(num) 2. Answer the following...
1. What will the following python code display? num = list(range(5)) print(num) 2. Answer the following questions using the list below. You can record your answers in the essay textbox. data = [5,3,7] A. Write code to replace the value in the 0 position with the number 8. B. Add the value 10 to the end of the list. C. Insert the value 22 after position 1 in the list. D. Remove the value at position 2. E. Sort the...