Page 340 - Artificial Intellegence_v2.0_Class_9
P. 340
10. Find the output of the following codes:
a. l1=[10,20,40,50] [10, 'abc', 'xyz', 50]
l1[1:3]=["abc","xyz"]
print(l1)
b. names=["yash","amit","rhea","mayank"] ['amit', 'mayank', 'rhea', 'yash']
names.sort()
print(names)
c. A=[10,20,34,56,"abc","xyz",89.5,67] [10, 20, 34, 56, 'xyz', 89.5]
A.remove("abc")
A.pop()
print(A)
d. l1=[1,2,3,4,5,6] [2, 3, 4, 5, 6, 1]
print(l1[1:]+l1[:1])
e. x=2 [1, 1][2, 2][3, 3][4, 4]
for i in range(1,5):
l=[i]*x
print(l,end='')
11. Write an algorithm to check if a number is an Armstrong number.
Ans. Step 1: Start
Step 2: Declare Variable sum, temp, n
Step 3: Read n from user
Step 4: Initialize Variable sum=0 and temp=n
Step 5: Repeat Until n>=0
sum=sum + cube of last digit i.e. [(n%10)*(n%10)*(n%10)]
n=n/10
Step 6: IF sum==temp
Print "Armstrong Number"
ELSE
Print "Not Armstrong Number"
Step 7: Stop
12. Write a short note on indexing. Define the different types of indexing.
OR
Write a menu-driven program to find the volume of a sphere and a cylinder
Ans. Indexing refers to the way of addressing an element in a list. Python supports two types of indexing, forward indexing
and negative indexing. Forward indexing is when the index number begins with 0 till length-1 and we refer the elements
from left to right. Negative indexing is when the index number begins with -1 till -length and we refer the elements
from right to left.
OR
print("Select the vessel whose volume you want to find: \n1. Sphere\n2. Cylinder")
a = int(input())
pi = 3.14
if(a == 1):
338 Touchpad Artificial Intelligence (Ver. 2.0)-IX

