Question

In: Computer Science

Given a list of fruits, fruits = ["apple", "pear", "banana", "cherry" ] which expression(s) will return...

Given a list of fruits, fruits = ["apple", "pear", "banana", "cherry" ]

which expression(s) will return the last two items in fruits in this order : cherry, banana?

a) fruits[-3:-1]

b) fruits[-1:-len(fruits) + 2:-1]

c) fruits[-1:-3:-1]

d) fruits[:-3:-1]

Which Python variable names are invalid?

a) 12MonthsTotal_Pay

b) TotalPay$

c) Total_January2019

d) JanuaryRateln%

what is the output of executing the code segment?

a, b, c = False, True, False

if a or b:

print('A', end = ' ')

else:

print('B', end = ' ')

if not b:

print('C', end = ' ' )

elif c :

print('D', end = ' ' )

else:

print('E', end = ' ' )

print()

a) A E

b) B E

c) A

d) None of the above

Suppose k = ["apple", "banana", "cherry"]

Which statement(s) when executed does not cause a run-time error?

a) del k["apple"]

b) k.sort(reverse = True)

c) k.get("apple", 'Not found')

d) All three statement do not cause a run-time error.

Solutions

Expert Solution

Solution(1) : Option(C) and Option(D) both are correct options here. Please check out the output in the below code for the same.

Solution(2) :   Option(A) , Option(B) , and Option(D) both are correct options here because we can not declare a variable in these three ways as these declarations are invalid. Please check out the output in the below code for the same.

Solution(3) : Option(A) " A E " is the correct option. Please check out the output in the below code for the same.

Solution(4) : Option(B) " k.sort(reverse = True) " is the correct option because it will not create any run time error while execution. Please check out the output in the below code for the same.


Related Solutions

Fruits=['mango','apple','orange','banana','grape'] prices=[15,12,17,7,19] 1. Using priceDict, find the price for 'grape'. 2. Add a price of 20...
Fruits=['mango','apple','orange','banana','grape'] prices=[15,12,17,7,19] 1. Using priceDict, find the price for 'grape'. 2. Add a price of 20 for 'pomegranate'. 3. Create a sorted list of all the prices in priceDict. 4. Calculate the average of all the prices in priceDict. 5. Update the price for 'pomegranate' to be 25. 6. Mangos has just sold out. Delete 'mango' and its price from priceDict. Python
[Javascript] Create a function(returnObjectFromId(case, ...idNum)) to return the case Object(s) for a given idNum, or list...
[Javascript] Create a function(returnObjectFromId(case, ...idNum)) to return the case Object(s) for a given idNum, or list of idNums. Calling with a single `idNum` value should return the case Object, and return NULL if an id value that's unknown is passed returnObjectFromId(case, 84838) would return the Object in the cases Array with an 'idNumber' of id, and use the .find() method of the cases Array to locate items by idNumber. returnObjectFromId(cases, -23298312) would return null. returnObjectFromId(cases, 161020, 161021) would return an...
What is an S-expression? What is a cons cell? What is an atom? A pair? A list?
What is an S-expression? What is a cons cell? What is an atom? A pair? A list? What do car and cdr do? What do the map and reduce functions do? Write a recursive function to compute the length of a list. Write a function to compute the length of a list using reduce.
Which equilibrium constant expression(s) are for the following reaction. I2(g)↔I2(solution) Choose from the list below and...
Which equilibrium constant expression(s) are for the following reaction. I2(g)↔I2(solution) Choose from the list below and enter the letters alphabetical order. (e.g. AH) A) (pI2)eq F) [I2(solution)]eq2 B) [I2(solution)]eq G) (pI2)eq-2 C) (pI2)eq-1 H) [I2(solution)]eq-2 D) [I2(solution)]eq-1    What is the equilibrium constant expression for the following reaction: Pb2+(aq) + 2I−(aq)↔PbI2(s) Choose from the list below and enter the letters alphabetical order. (e.g. For an equilibrium constant of [I-]2eq[Pb2+]eq enter AH.) A) [Pb2+]eq E) [I-]-1eq I) (XPbI2)2eq B) [I-]eq F)...
Write a program to remove the node of Fruit type which contains “Banana” from a given...
Write a program to remove the node of Fruit type which contains “Banana” from a given linked list and then print the updated linked list. Part of the program is given below but it is incomplete. You need to complete it. You should create your own data file. After you complete the program, please check it carefully to ensure it can handle the following cases: Banana is the first node in the linked list. Banana is not the first node...
def num_to_digit_rec(num, base): """ Return a list of digits for num with given base; Return an...
def num_to_digit_rec(num, base): """ Return a list of digits for num with given base; Return an empty list [] if base < 2 or num <= 0 """ # Write your code here return [] def digit_sum(num, base): """ Return the sum of all digits for a num with given base Your implementation should use num_to_digit_rec() function """ # Write your code here return 0 def digit_str(num, base): """ Given a number and a base, for base between [2, 36]...
In Python, Given a list of numbers, return a list where all adjacent == elements have...
In Python, Given a list of numbers, return a list where all adjacent == elements have been reduced to a single element, so [1,2,2,3,3,2,2,4] returns [1,2,3,2,4]. You may create a new list or modify the passed in list (set function does not work in this case).
#Write a program in Python that given a list of positive integers, return another list where...
#Write a program in Python that given a list of positive integers, return another list where each element corresponds to the sum of the digits of the elements o#f the given list. #Example: # input # alist=[124, 5, 914, 21, 3421] # output # sum=[7, 5, 14, 3, 18]
Which is the correct equilibrium constant expression for the following reaction? 2 KClO3(s) ⇌ 2 KCl(s)...
Which is the correct equilibrium constant expression for the following reaction? 2 KClO3(s) ⇌ 2 KCl(s) + 3 O2(g) A. Kc = [KCl]2 [O2]3 / [KClO3]2 B. Kc = [O2]3 C. Kc = [O2] D. Kc = [KCl] E. Kc = [KCl] [O2] / [KClO3]
I have Stock Return of two Companies MSFT(Microsoft) and APPL (Apple).It is mentioned in the given...
I have Stock Return of two Companies MSFT(Microsoft) and APPL (Apple).It is mentioned in the given Table.The Question is : ' ''We would also like to check whether both stocks (Apple and Microsoft) have the same return on average. Using the confidence interval approach, perform and present an appropriate hypothesis test at the 5% level of significance, and interpret your result. Which stock would you prefer and why? [Hint: Hypothesis test about two population means. Zero marks if you test...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT