You are on page 1of 3

LAB REPORT#2

NOOR FATIMA

ROLL NO#42

BATCH 08

AI LAB
PRINT NUMBER WITH IF ELSE:
num =int(input('write input number='))
if(num >0):
print(num)
else:
print('end')
OUTPUT:
write input number=6
6
SAVING VALUE OF X IN Y
x =int(input("enter value of x:"))
if (x<10):
y=x
print("value of y is=",y)
OUTPUT:
enter value of x:8
value of y is= 8
PRINT VALUE OF EXPRETION:
var=100
if(var==100):
print("value of expression is 100")
#don't give space it will caue error
print('good bye')
OUTPUT:
value of expression is 100
good bye
IF ELSE
print("IF ELSE")
var1=100
if (var1):
print('1-got a true expression value')
print(var1)
var2=0
if(var2):
print("2-got a true expression value")
print(var2)
print('goodbye')#without space will run for both
OUTPUT:
IF ELSE
1-got a true expression value
100
Goodbye
NESTED IF ELSE
print("NESTED IF ELSE")
t=10
s=7
l=1
if(t>s & t>l):
print(t," is greatest")
elif (s>t & s>l):
print(s," is greatest")
else:
print(l,'is greatest')

OUTPUT:
NESTED IF ELSE
10 is greatest
COUNT ALL THE NUMBERS
count=0
while(count<9):
print('the count is:',count)
count=count+1

print("good bye")
OUTPUT:
the count is: 0
the count is: 1
the count is: 2
the count is: 3
the count is: 4
the count is: 5
the count is: 6
the count is: 7
the count is: 8
good bye
WHILE NOT LOOP
done=False
while not done:
entry=int(input("enter num="))
if(entry==999):
done=True
print('true')
else:
print(entry)
OUTPUT:
enter num=4
4
enter num=99
99
enter num=999
true
STOP USING WHILE:
n=1
stop=int(input("feed the value stop"))
while (n<=stop):
print(n)
n+=1
OUTPUT:
feed the value stop6
1
2
3
4
5
6
LESS THAN IN WHILE
count=0
while(count<5):
print(count,"is less than 5")
count=count+1
else:
print(count,"is not less than 5")
OUTPUT:
0 is less than 5
1 is less than 5
2 is less than 5
3 is less than 5
4 is less than 5
5 is not less than 5
LINEAR SEARCH:
def linear_search(A,k):
for element in A:
if element==k:
print('k is found')
print('k is not found')
A=[3,5,11,6,9,23,12,13,4]
k=12
print(linear_search(A,k))
OUTPUT:
k is not found
k is not found
k is not found
k is not found
k is not found
k is not found
k is found
k is not found
k is not found
k is not found
None

You might also like