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

Python Programs

The document outlines a series of Python programming tasks for an AI Practical Exam, including creating and manipulating lists of names and numbers. It details specific operations such as adding, removing, and sorting list items, as well as calculating sums and modifying elements. Each task is accompanied by example code and expected output.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

Python Programs

The document outlines a series of Python programming tasks for an AI Practical Exam, including creating and manipulating lists of names and numbers. It details specific operations such as adding, removing, and sorting list items, as well as calculating sums and modifying elements. Each task is accompanied by example code and expected output.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Do the following questions and submit the hardcopies on the day of

AI Practical Exam.
Write the programs in Python to-
1) Create a list in Python of children selected for science quiz with
following names: Arjun, Sonakshi, Vikram, Sandhya, Sonal, Isha,
Kartik.
Perform the following tasks on the list in sequence-
a. Print the whole list
b. Delete the name “Vikram” from the list
c. Add the name “Jay” at the end
d. Remove the item which is at the second position.

2) Create a list num=[23,12,5,9,65,44]


a. print the length of the list
b. print the elements from second to fourth position using positive
indexing
c. print the elements from position third to fifth using negative
indexing

3) Create a list of first 10 even numbers, add 1 to each list item and
print the final list.

4) Program to find the sum of all numbers stored in a list.

5) Create a list List_1= [10, 20, 30, 40]. Add the elements [14, 15, 12]
using extend function. Now sort the final list in ascending order and
print it
1) Create a list in Python of children selected for science quiz with following names: Arjun,
Sonakshi, Vikram, Sandhya, Sonal, Isha, Kartik.
Perform the following tasks on the list in sequence-
a. Print the whole list
b. Delete the name “Vikram” from the list
c. Add the name “Jay” at the end
d. Remove the item which is at the second position.

CODE:
quiz_list = ["Arjun", "Sonakshi", "Vikram", "Sandhya",
"Sonal", "Isha", "Kartik"]
print("Original List:", quiz_list)
quiz_list.remove("Vikram")
print("After removing Vikram:", quiz_list) OUTPUT:
quiz_list.append("Jay")
print("After adding Jay:", quiz_list) Original List: ['Arjun', 'Sonakshi', 'Vikram',
quiz_list.pop(1) 'Sandhya', 'Sonal', 'Isha', 'Kartik']
print("After removing second position item:", After removing Vikram: ['Arjun',
'Sonakshi', 'Sandhya', 'Sonal', 'Isha',
quiz_list)
'Kartik']
After adding Jay: ['Arjun', 'Sonakshi',
'Sandhya', 'Sonal', 'Isha', 'Kartik', 'Jay']
After removing second position item:
['Arjun', 'Sandhya', 'Sonal', 'Isha', 'Kartik',
'Jay']
2) Create a list num=[23,12,5,9,65,44]
a. print the length of the list
b. print the elements from second to fourth position using positive indexing
c. print the elements from position third to fifth using negative indexing

CODE:

num = [23, 12, 5, 9, 65, 44] OUTPUT


print("Length of the list:", len(num)) Length of the list: 6
print("Elements from 2nd to 4th position:", Elements from 2nd to 4th position:
[12, 5, 9]
num[1:4]) Elements from 3rd to 5th position
print("Elements from 3rd to 5th position using negative indexing: [5, 9, 65]
-
using negative indexing:", num[-4:-1])
3) Create a list of first 10 even numbers, add 1 to each list
item and print the final list.

CODE:

even_numbers = [i * 2 for i in range(1, 11)]


modified_list = [num + 1 for num in even_numbers]
print("Final List:", modified_list)

OUTPUT

Final List: [3, 5, 7, 9, 11,


13, 15, 17, 19, 21]
4) Program to find the sum of all numbers stored in a list.

CODE:

numbers = [10, 20, 30, 40, 50]


total_sum = sum(numbers)
print("Sum of all numbers in the list:", total_sum)

OUTPUT

Sum of all numbers in


the list: 150
5) Create a list List_1= [10, 20, 30, 40]. Add the elements [14, 15, 12] using
extend function. Now sort the final list in ascending order and print it

CODE:

List_1 = [10, 20, 30, 40]


List_1.extend([14, 15, 12])
List_1.sort()
print("Final Sorted List:", List_1)

OUTPUT

Final Sorted List: [10, 12,


14, 15, 20, 30, 40]

You might also like