0% found this document useful (0 votes)
58 views6 pages

Q#1Take A Sample List (2, 1, 3, 5, 4, 3, 8) Apply Del, Remove, Sort, Insert, Pop, Extend )

This document contains questions about Python list methods and operations, including using del(), remove(), sort(), insert(), and pop() on a sample list. It also asks about writing expressions to calculate ladder height given length and angle, and using list operators and methods like finding the index and value of the middle element and sorting in descending order. Further questions involve assigning lists and tuples of month strings and performing operations like inserting, appending, popping, removing, and reversing order.

Uploaded by

Mehnoor Siddiqui
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views6 pages

Q#1Take A Sample List (2, 1, 3, 5, 4, 3, 8) Apply Del, Remove, Sort, Insert, Pop, Extend )

This document contains questions about Python list methods and operations, including using del(), remove(), sort(), insert(), and pop() on a sample list. It also asks about writing expressions to calculate ladder height given length and angle, and using list operators and methods like finding the index and value of the middle element and sorting in descending order. Further questions involve assigning lists and tuples of month strings and performing operations like inserting, appending, popping, removing, and reversing order.

Uploaded by

Mehnoor Siddiqui
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

LAB TASK – 06

Q#1Take a sample list [2, 1, 3, 5, 4, 3, 8]


Apply del(), remove(), sort(), insert(), pop(), extend()…)
CODE:

OUTPUT:
2. A ladder put up right against a wall will fall over unless put up at a certain angle less than
90 degrees. Given variables length and angle storing the length of the ladder and the angle
that it forms with the ground as it leans against the wall, write a Python expression involving
length and angle that computes the height reached by the ladder. Evaluate the expression for
these values of length and angle
(a)16 feet and 75 degrees
CODE:

OUTPUT:

(b)20 feet and 0 degrees


CODE:

OUTPUT:

(c)24 feet and 45 degrees


CODE:

OUTPUT:
(d)24 feet and 80 degrees
CODE:

OUTPUT:

Q3. Write the relevant Python expression or statement, involving a list of numbers list and
using list operators and methods for these specifications:
(a)An expression that evaluates to the index of the middle element of list
(b)An expression that evaluates to the middle element of list
(c)A statement that sorts the list list in descending order
(d)A statement that removes the first number of list lst and puts it at the end
CODE:

OUTPUT:
4. Start by assigning to variables monthsL and monthsT a list and a tuple, respectively,
both containing strings 'Jan', 'Feb', 'Mar', and 'May', in that order. Then attempt the
following with both containers:
(a)Insert string 'Apr' between 'Mar' and 'May'.
(b)Append string 'Jun'.
(c)Pop the container.
(d)Remove the second item in the container.
(e)Reverse the order of items in the container
FOR LIST:
CODE:

OUTPUT:

FOR TUPLE:
CODE: (a)

OUTPUT:

CODE: (b)
OUTPUT:

CODE: (c)

OUTPUT:

CODE: (d)

OUTPUT:

CODE: (e)

OUTPUT:

CODE: (f)

OUTPUT:

6. Write the corresponding Python assignment statements:


(a)Assign 6 to variable a and 7 to variable b.
(b)Assign to variable c the average of variables a and b.
(c)Assign to variable inventory the list containing strings 'paper', 'staples', and 'pencils'.
(d)Assign to variables first, middle and last the strings 'John', 'Fitzgerald', and 'Kennedy'.
(e)Assign to variable fullname the concatenation of string variables first, middle, and last.
Make sure you incorporate blank spaces appropriately.

You might also like