Ad Code

Python AKTU Quiz 2 Answer 2 | Prutor.ai


   

Programmer for Noobs

PYTHON Quiz 2 Answers

Q1.  If list= ['red’, 'blue' , 'green' , 'yellow'] , what will be the output of :
        list. Pop('blue')
        print(list)

1.yellow

2.red', 'blue', 'green'

3.blue', 'green', 'yellow'

4.error

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

If we run this code in the interpreter .list pop() print (list) gives us error as this code is invalid.

Programmer for Noobs

Q2. Which function will remove an item from a list?

1.del()

2.remove()

3.pop()

4. All of the above

Reason: This method deletes the element at the position mentioned in its arguments.

*The pop() function is used to remove an item from a list, as this is used to remove mentioned elements entered by the user or written in the argument.



Programmer for Noobs


Programmer for Noobs Q3.  If list=['suzuki', 'subaru', 'honda', 'maruti'] , what will be the output of
        print(list[3])
        after running the code :
        list.sort(reverse=True) ?

1.suzuki

2.subaru

3.honda

4.maruti


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

Programmer for Noobs

Q4. Which statement is correct?

1.sorted() method sorts the items in ascending order

2.sorted() method maintains the sorted order of the items in the list

3.Both A and B

4.Neither A nor B

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

Programmer for Noobs

Programmer for Noobs Q5. Which method is used to arrange the items of a list in ascending order in python?

1.sort()

2.arrange()

3.sort(reverse=True)

4.ascend()

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

Programmer for Noobs Q6. Which of the following is used for performing repetitive tasks in Python?

1.Counters

2.Lists

3.Arrays

4.Loops

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

Programmer for Noobs 


Q7.  How is a line, or a group of lines, related to the rest of the python program?

1.square brackets []

2.indentation

3.braces {}

4.parentheses () 

Reason: Indentation line a group of lines related to the rest of the program. To indicate a block of code in Python, you must indent each line of the block by the same whitespace.

Programmer for Noobs Q8.  If numbers=[1, 2, 3, 4, 5] , then how to get the largest value of this list?

1.high(numbers)

2.max(numbers)

3.large(numbers)

4.sum(numbers)

Reason: 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.

Programmer for Noobs 

Programmer for Noobs Q9. What should come in place of X if we want to print HI! 6 times?
        for i in range(X):
            print('HI!'')

1.1,5

2.1,6

3.5

4.1,7

Reason: 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.

Programmer for Noobs 







Programmer for Noobs Q10. Which of the following is a valid singleton tuple?

1.single=(1)

2.single=1,

3.single=()

4.single=1

Reason: 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)

Programmer for Noobs

Please subscribe to our channel 



Post a Comment

0 Comments