AI-Python Codes-IX-2023-24
AI-Python Codes-IX-2023-24
PRINT 1 To print personal information like Name, Father’s Name, Class, School Name.
print(“*”)
print(“* *”)
print(“* * *”)
print(“* * * *”)
print(“* * * * *”)
print(“* * * * *”)
print(“* * * *”)
print(“* * *”)
print(“* *”)
print(“* ”)
• Create a list in Python of children selected for science quiz with following names-
LIST Arjun, Sonakshi, Vikram, Sandhya, Sonal, Isha, Kartik
Perform the following tasks on the list in sequence-
○ Print the whole list
○ Delete the name “Vikram” from the list
○ Add the name “Jay” at the end
○ Remove the item which is at the second position.
n=["Arjun", "Sonakshi", "Vikram", "Sandhya", "Sonal", "Isha", "Kartik"]
print(n)
n.pop(2)
n.append("jay")
print(n)
n.pop(2)
print(n)
• Create a list num=[23,12,5,9,65,44]
○ Print the length of the list
○ Print the elements from second to fourth position using positiveindexing
○ Print the elements from position third to fifth using negative indexing
num=[23,12,5,9,65,44]
print(num)
print(len(num))
print(num[2:5:1])
print(num[-2:-5:-1])
• Create a list of first 10 even numbers, add 1 to each list item and print the final list.
• 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.
even = [2,4,6,8,10,12,14,16,18,20]
value=1
list2=[]
for i in even:
list2.append(i+value)
print("Final List: ",list2)
List_1=[10,20,30,40]
List_1.extend([14,15,12] )
print(List_1)
List_1.sort()
print(List_1)
• Program to check if a person can vote
IF, age = int(input("enter your age ="))
FOR, if age>=18:
print("you are eligible for vote")
WHILE
else:
print("you are not eligible for vote")
• Input a number and check if the number is positive, negative or zero and display
an appropriate message
num = int(input("enter a number ="))
if num>0:
print("Number is positive")
elif num==0:
print("number is zero")
else:
print("number is negative")
• To print first 10 natural numbers
for i in range(1,11,1):
print(i)