MyProgrammingLab Starting out with
Python Ch.7
TEST BANK MyProgrammingLab Starting out with
Python Ch.7 -2nd-edition- tony-gaddis. Examination
Study Guide 2023, Exams of Statistics
Write a statement that defines plist to be the empty list. -
✔✔ANSWER✔✔-plist=[]
Write a statement that defines plist as the list containing exactly these
elements (in order): "spam", "eggs", "vikings" . - ✔✔ANSWER✔✔-
plist=['spam','eggs','vikings']
Write statement that defines plist to be a list of the following ten
elements: 10, 20, 30, ..., 100 in that order. - ✔✔ANSWER✔✔-
plist=[10,20,30,40,50,60,70,80,90,100]
,MyProgrammingLab Starting out with
Python Ch.7
Create a list named tax_rates, consisting of the following five elements:
0.10, 0.15, 0.21, 0.28, 0.31, in that order. - ✔✔ANSWER✔✔-
tax_rates=[0.10,0.15,0.21,0.28,0.31]
Write a statement that defines the variable denominations, and
associates it with a list consisting of the following six elements: 1, 5, 10,
25, 50, 100, in that order. - ✔✔ANSWER✔✔-
denominations=[1,5,10,25,50,100]
Associate True with the variable has_dups if the list list1 has any
duplicate elements (that is if any element appears more than once),
and False otherwise. - ✔✔ANSWER✔✔-has_dups = len(list1) >
len(list(set(list1)))
Given that plist has been defined to be a list of 30 elements, add 5 to its
last element. - ✔✔ANSWER✔✔-plist[-1] += 5
Assume that a list of integers named salary_steps that contains exactly
five elements has been defined.
Write a statement that changes the value of the last element in the list
to 160000. - ✔✔ANSWER✔✔-salary_steps[-1]=160000
,MyProgrammingLab Starting out with
Python Ch.7
Given a variable plist, that refers to a non-empty list, write an
expression that refers to the first element of the list. - ✔✔ANSWER✔✔-
plist[0]
Given a variable plist, that refers to a list with 34 elements, write an
expression that refers to the last element of the list. - ✔✔ANSWER✔✔-
plist[-1]
Assume that the variable plist has been defined and refers to a list.
Write a statement that assigns the next to last element of the list to x. -
✔✔ANSWER✔✔-x=plist[-2]
Given that a variable named plist has been defined and refers to a non-
empty list, write a statement that associates its first element with 3. -
✔✔ANSWER✔✔-plist[0]=3
Assume that salary_steps refers to a non-empty list, write a statement
that assigns the value 30000 to the first element of this list. -
✔✔ANSWER✔✔-salary_steps[0]=30000
Assume that plist has been defined and is associated with a non-empty
list. Write a statement that increases the first element of this list by 10.
- ✔✔ANSWER✔✔-plist[0]+=10
, MyProgrammingLab Starting out with
Python Ch.7
Assume that a variable named plist refers to a list with 12 elements,
each of which is an int. Assume that the variable k refers to a value
between 0 and 6. Write a statement that assigns 15 to the list element
whose index is k. - ✔✔ANSWER✔✔-plist[k]=15
Given that plist refers to a non-empty list ,write a statement that
assigns the int
-1
to the last element of the list. - ✔✔ANSWER✔✔-plist[-1]=-1
Assume that plist is associated with a list that has 12 elements. Assume
further that k refers to an int between 2 and 8. Assign 9 to the element
just after the element in plist whose index is k . - ✔✔ANSWER✔✔-
plist[k+1]=9
Assume that a variable named plist has been defined and is associated
with a list that consists of 12 elements. Assume further that k refers to
an int between 2 and 8. Assign 22 to the element just before the
element in plist whose index is k . - ✔✔ANSWER✔✔-plist[k-1]=22