0% found this document useful (0 votes)
30 views9 pages

Programs Set2

Uploaded by

saluiamanda
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)
30 views9 pages

Programs Set2

Uploaded by

saluiamanda
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
You are on page 1/ 9

#Program to check a number is positive or negative.

n=int(input("Enter a number:-"))
if n>0:
print("The number is positive.")
elif n<0:
print("The number is negative.")
else:
print("The number is zero.")
#Program to check a number is even or odd.
n=int(input("Enter a number:-"))
if n%2==0:
print("The number is even.")
else:
print("The number is odd.")
#Program to display the greater number among two numbers.
n=int(input("Enter the first number:-"))
n1=int(input("Enter the second number:-"))
if n>n1:
print(n,"is the greater number.")
else:
print(n1,"is the greater number.")
#Program to display the greater number among three numbers.
a=int(input("Enter the first number:-"))
b=int(input("Enter the second number:-"))
c=int(input("Enter the third number:-"))
if a>b and a>c:
print(a,"is the greater number.")
if b>a and b>c:
print(b,"is the greater number.")
if c>a and c>b:
print(c,"is the greater number.")
#Program to convert distance from Meter to KM and meter
ch=int(input("Enter 1 for Meter to KM / Enter 2 for KM to Meter-"))
if ch==1:
d=float(input("Enter the distance in Meter-:"))
km=d/1000
print("The distance in KM-:",km)
elif ch==2:
d=float(input("Enter the distance in KM-:"))
m=d*1000
print("The distance in Meter-:",m)
else:
print("Wrong choice")
#Program to find volume of a Sphere and a Cuboid
ch=int(input("Enter 1 for volume of Sphere / Enter 2 for volume of Cuboid-"))
if ch==1:
r=int(input("Enter the radius of the Sphere-:"))
v=4/3*22/7*(r**3)
print("The volume of Sphere is-:",v)
elif ch==2:
l=int(input("Enter the length of the Cuboid-:"))
b=int(input("Enter the breadth of the Cuboid-:"))
h=int(input("Enter the height of the Cuboid-:"))
v=l*b*h
print("The volume of Cuboid is-:",v)
else:
print("Wrong choice")
#Program to create simple calculator performing only 4 basic operations
a=int(input("Enter a number-:"))
b=int(input("Enter another number-:"))
print("Addition-:",a+b)
print("Subtraction-:",a-b)
print("Multiplication-:",a*b)
print("Division-:",a/b)
#Program to check a year is leap year or not
year=int(input("Enter a valid year-:"))
if year%400==0:
print("The year is leap year")
elif year%4==0:
print("The year is leap year")
else:
print("The year is not a leap year")
#Program to print the even numbers with in a range
start=int(input("Enter the start value of the range-:"))
stop=int(input("Enter the stop value of the range-:"))
print("The even numbers are-:")
for i in range(start,stop+1):
if i%2==0:
print(i)
#Program to print the sum of natural numbers with in a range
start=int(input("Enter the start value of the range-:"))
stop=int(input("Enter the stop value of the range-:"))
s=0
for i in range(start,stop+1):
s=s+i
print("The sum of natural numbers is-:",s)
#Program to count number of vowels in a string
str1=input("Enter the string-:")
vowels='aeiouAEIOU'
l=len(str1)
c=0
for i in range(0,l):
if str1[i] in vowels:
c=c+1
print("The number of vowels is-:",c)
#Program to check a string is palindrome or not
str1=input("Enter the string-:")
if str1==str1[: : -1]: #str1[: : -1] mean reverse of string
print("The string is palindrome")
else:
print("The string is not palindrome")
#Program to print the lowest number from a list enter by the user
n=int(input("Enter the length of the list-:"))
l=[]
for i in range(1,n+1):
e=int(input("Enter the element of the list-:"))
l.append(e)
print("The list is-:",l)
mn=l[0]
for i in range(0,n):
if mn>l[i]:
mn=l[i]
print("The lowest number in the list is-:",mn)
#Program to print the numbers divisible by both 3 & 7 from a list enter by the
user
n=int(input("Enter the length of the list-:"))
l=[]
for i in range(1,n+1):
e=int(input("Enter the element of the list-:"))
l.append(e)
print("The list is-:",l)
print("The numbers divisible by both 3 & 7 are-:")
for i in range(0,n):
if l[i]%3==0 and l[i]%7==0:
print(l[i])
#Program to reverse a number
n=int(input("Enter the number:-"))
s=0
while n>0:
r=n%10
s=s*10+r
n=n//10
print("The reverse of the number is:-",s)
#Program to check a number is palindrome or not.
n=int(input("Enter the number:-"))
copy=n
s=0
while n>0:
r=n%10
s=s*10+r
n=n//10
if copy==s:
print("The number is Palindrome number.")
else:
print("The number is not Palindrome number.")
#Program to check the number is prime or not.
n=int(input("Enter the number:-"))
f=0
for i in range(2,n):
if n%i==0:
f=1
break
if f==0:
print("The number is Prime number.")
else:
print("The number is not Prime number.")
#Program to print the factors of the a number.
n=int(input("Enter the number:-"))
print("The factors of the number are:-")
for i in range(1,n+1):
if n%i==0:
print(i)
#Program to check a number is perfect number or not.
#Sum of the factor (except the number) equal to the number (eg. 6)
n=int(input("Enter the number:-"))
s=0
for i in range(1,n):
if n%i==0:
s=s+i
if s==n:
print("The number is Perfect number.")
else:
print("The number is not Perfect number.")
#Program to find GCD/HCF of two numbers
n=int(input("Enter the first number:-"))
n1=int(input("Enter the second number:-"))
gcd=1
i=1
while i<=n and i<=n1:
if n%i==0 and n1%i==0:
gcd=i
i=i+1
print("The GCD/HCF of the numbers:-",gcd)
#Program to check a number is Armstrong number or not
#Sum of cube of the digit equal to the number
n=int(input("Enter the first number:-"))
copy=n
s=0
while n>0:
r=n%10
s=s+r**3
n=n//10
if copy==s:
print("The number is Armstrong number.")
else:
print("The number is not Armstrong number.")
#Program to print factorial of a number
n=int(input("Enter the first number:-"))
fact=1
for i in range(1,n+1):
fact=fact*i
print("The factorial of the number is:-",fact)
#Program to check a number is special number or not.
#sum of the factorial of digits equal to the number (eg. 145)
n=int(input("Enter the first number:-"))
copy=n
s=0
while n>0:
fact=1
r=n%10
for i in range(1,r+1):
fact=fact*i
s=s+fact
n=n//10
if copy==s:
print("The number is Speacial Number.")
else:
print("The number is not Special Number.")

You might also like