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

Python Programs for Class X AI

Uploaded by

vandika186
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)
8 views6 pages

Python Programs for Class X AI

Uploaded by

vandika186
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

Revision - 2

Artificial Intelligence (Subject Code: 417)


Python Programs – Class X

# write a program to input a number and check whether it is divisible


of 5 or not.

no=int(input("Enter a number"))
if(no%5==0):
print("no is divisible by 5")
else:
print("no is not divisible by 5")

# write a program to input a number and check whether it is divisible


of 5 and 7 or not.

no=int(input("Enter a number"))
if(no%5==0 and no%7==0):
print("no is divisible by 5 and 7")
else:
print("no is not divisible by 5 and 7")

# write a program to check whether the entered character is vowel or


not.

ch=input("Enter any character")


if(ch=='a' or ch=='e' or ch=='i' or ch=='o' or ch=='u'):
print("vowel")
else:
print("consonant")

# write a program to calculate area of rectangle, if shape entered is


r otherwise calculate area of square, if shape entered is s.

shape=input("Enter r for rectangle / s for square")


if(shape=='r'):
len=int(input("enter length"))
br=int(input("enter breadth"))
area=len*br
print("area of rectangle is ",area)
elif(shape=='s'):
side=int(input("enter side"))
area=side*side
print("area of square is ",area)
else:
print("enter r or s only")
# write a program to check whether the triangle is equilateral triangle
or not

side1=int(input("Enter a number"))
side2=int(input("Enter a number"))
side3=int(input("Enter a number"))

if(side1==side2==side3):
print("Equilateral triangle")
elif(side1==side2 or side2==side3 or side1==side3):
print("isosceles triangle")
else:
print("Scalene triangle")

# write a program to swap the value of two variables using third


variable.

a=int(input("enter first no"))


b=int(input("enter sec no"))
print("Before Swap")
print("first no",a)
print("second no",b)
c=a
a=b
b=c
print("After Swap")
print("first no",a)
print("second no",b)

# write a program to swap the value of two variables without using


third variable.

a=int(input("enter first no"))


b=int(input("enter sec no"))
print("Before Swap")
print("first no",a)
print("second no",b)
a=a+b
b=a-b
a=a-b
print("After Swap")
print("first no",a)
print("second no",b)
# Write a program to input two numbers and an operator from the user.
Display the result calculated based on the operator entered.

n1=int(input("Enter First No"))


n2=int(input("Enter Second Number"))
op=input("Enter Operator +, - ,*, / only")
if(op=="+"):
res=n1+n2
print("Result ",res)
elif(op=="-"):
res=n1-n2
print("Result ",res)
elif(op=="*"):
res=n1*n2
print("Result ",res)
elif(op=="/"):
res=n1/n2
print("Result ",res)
else:
print("Enter +,-,*,/ only")

# Write a program to input price, quantity and calculate the bill. If


the billing amount is more than 5000 then discount is 15% otherwise
discount is 10%.

price=int(input("Enter price"))
qty=int(input("Enter quantity"))
bill=price*qty
if(bill>5000):
discount=bill*0.15
amount=amount-dicount
print("Bill after discount ",amount)
elif(bill>2000):
discount=bill*0.10
amount=amount-dicount
print("Bill after discount ",amount)
else:
print("no discount")

# write a program to input a number and check the sum of digit

no=int(input("Enter a number"))
rem=0
sum=0
while(no>0):
quo=no//10
rem=no%10
sum=sum+rem
no=quo
print("sum of digit ",sum)

# write a program to input a number and check the reverse of digit

no=int(input("Enter a number"))
rem=0
rev=0
while(no>0):
quo=no//10
rem=no%10
rev=(rev*10)+rem
no=quo

print("sum of digit ",rev)

# write a program to input a number and check whether digit is


palindrome or not

no=int(input("Enter a number"))
temp=no
rem=0
rev=0
while(no>0):
quo=no//10
rem=no%10
rev=(rev*10)+rem
no=quo

print("sum of digit ",rev)

if(temp==rev):
print("palindrome")
else:
print("not a palindrome")

# write a program to input a number and print the sum of natural numbers
from 1 to 10

i=1
sum=0
while(i<=10):
sum=sum+i
i=i+1

print ("sum of natural numbers", sum)


# write a program to input a number and print the sum of evens and
odds from 1 to 10

sume=0
sumo=0
i=1
sum=0
while(i<=10):
if(i%2==0):
sume=sume+i
else:
sumo=sumo+i

i=i+1

print ("sum of evens", sume)


print ("sum of odds", sumo)

# write a program to input a number and print the series

1,4,7,10 ... till the entered no

no=int(input("Enter a number"))
i=1
while(i<=no):
print(i)
i=i+3

# write a program to print even numbers in 1 to 5


i=1
while(i<=5):
if(i%2==0):
print(“even no”,i)
i=i+1

# write a program to print odd numbers in 1 to 5


i=1
while(i<=5):
if(i%2!=0):
print(“odd no”,i)
i=i+1
# write a program to print square if no is even otherwise print cube
in 1 to 10

i=1
while(i<=10):
if(i%2==0):
sq=i*i
print("square",sq)
else:
cu=i*i*i
print("cube",cu)

i=i+1

You might also like