Python Week 2 Quiz Answers



Disclaimer for Pruto-ai

If you require any more information or you have any problem regarding Copyright or have any questions about our site’s disclaimer, please feel free to contact us by email at contact@prutor-ai.com.

All the information on this website is published in good faith and for general information and educational purpose only. Prutor-ai does not make any warranties about the completeness, reliability, and accuracy of this information. Any action you take upon the information you find on this website (Prutor-ai.blogspot.com), is strictly at your own risk. will not be liable for any losses and/or damages in connection with the use of our website.

In this students get weekly assignments that they have to complete every week. Here we will show you or give you all the answers for the python quiz, These answers are for all those who have confusion in the questions or they don’t want to submit wrong answers.

 or if you haven’t, then its a good time to check the answers first and then submit.

[1] If list=[‘red’ , ‘blue’ , ‘green’ , ‘yellow’] , what will be the output of : list.pop() print (list) ?

  (a): yellow

  (b): red’, ‘blue’, ‘green’

  (c): blue’, ‘green’, ‘yellow’

  (d): error

Answer:(d) error

Explanation : The output of .list pop() print (list) is error because this code are wrong.

 

 

[2] If you want to use an item after you remove from what, which function should you use?

  (a): del()

  (b): not possible

  (c): remove()

  (d): pop()

Answer: (d) pop()

Explanation: pop() should you use because this method deletes the element at the position mentioned in its arguments.

 

[3] If list=[‘suzuki’, ‘subaru’, ‘honda’, ‘maruti’] , what will be the output of print(list[3]), after running the function : list.sort(reverse=True) ?

  (a): suzuki

  (b): subaru

  (c): honda

  (d): maruti

Answer: (c) honda

Explanation: The output is honda, because it is number 3 on the list.

 

 

[4] Which statement is correct?

  (a): sorted() method sorts the items in ascending order


  (b): sorted() method maintains the sorted order of the items in the list

  (c): Both A and B

  (d): Neither A nor B

Answer: (a) sorted() method sorts the items in ascending order

Explanation: sorted() sorts any sequence (list, tuple) and always returns a list with the elements in sorted manner, without modifying the original sequence.

 

 

[5] Which method is used to arrange the items in a list in ascending order?

  (a): sort()

  (b): arrange()

  (c): sort(reverse=True)

  (d): ascend()

Answer: (a) sort()

Explanation: The sort() method sorts the elements of a given list in a specific ascending or descending order.

 

 

[6] What is used for performing a repetitive tasks in Python?

  (a): Counters

  (b): Lists

  (c): Arrays

  (d): Loops

Answer: (d) loops

Explanation: loops is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).

 

 

[7] How is a line, or a group of lines related to the rest of the program?

  (a): square brackets []

  (b): indentation

  (c): braces {}

  (d): parentheses ()

Answer: (b) indentation

Explanation: Indentation line a group of lines related to the rest of the program.


[8] If numbers=[1, 2, 3, 4, 5] , then how to get the largest value of this list?

  (a): high(numbers)

  (b): max(numbers)

  (c): large(numbers)

  (d): sum(numbers)

Answer: (b) max(numbers)

Explanation: The max() function returns the item with the highest value, or the item with the highest value in an iterable. If the values are strings, an alphabetically comparison is done.

 

 

 

[9] What should come in the blank if we want to print HI! 6 times? for i in

range(        ): print(“HI!”)

  (a): 1,5

  (b): 1,6

  (c): 5

  (d): 1,7

Answer: (d) 1,7

Explanation: We use range(stop) to create a range of 0 to stop where stop is the number of lines desired. We use a for-loop to iterate through this range, concatenate the string to itself by the number of times desired and print the result.

 

[10] Which of the following is a valid singleton tuple?

  (a): single=(1)

  (b): single=1,

  (c): single=()

  (d): single=1

Answer: (b) single=1,

Explanation: A tuple of one item (a ‘singleton’) can be formed by affixing a comma to an expression (an expression by itself does not create a tuple, since parentheses must be usable for grouping of expressions).