0% found this document useful (0 votes)
19 views7 pages

PROGAM of 11

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views7 pages

PROGAM of 11

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

#Program 1

num1=float(input("Enter a number 1: "))


num2=float(input("Enter a number 2: "))
op=input("Enter operator[+,-,*,/,%]: ")
result=0
if op=='+':
OUTPUT
result=num1+num2
Enter a number 1: 3
elif op=='-':
result=num1-num2 Enter a number 2: 67

elif op=='/': Enter operator[+,-,*,/,%]: +


result=num1/num2 3.0 + 67.0 = 70.0
elif op=='*':
result=num1*num2
elif op=='%':
result=num1%num2
else:
print("invalid operator")
print(num1,op,num2,"=",result

#program 3
#to check weather a year is leap year or not
OUTPUT
year=int(input("enter year number: "))
enter year number: 2000
if (year % 4 == 0 and year % 100 != 0) or
2000 is a leap year.
(year % 400 == 0):
print(f"{year} is a leap year.")
else:
print(f"{year} is not a leap year.")
# program 4
#to calculate the area of cylinder and sphere
radiusc=int(input("enter the radius of a cylinder "))
heightc=int(input("enter the height of a cylinder "))
radiuss=int(input("enter the radius of a sphere "))
pi=3.14
volume_cylinder = pi * (radiusc ** 2) * heightc
print(f"The volume of the cylinder with radius {radiusc} and height {heightc} is
{volume_cylinder:.2f} cubic units.")

# Sphere volume calculation


volume_sphere = (4/3) * pi * (radiuss ** 3)
print(f"The volume of the sphere with radius {radiuss} is {volume_sphere:.2f}
cubic units

OUTPUT
enter the radius of a cylinder 3
enter the height of a cylinder 4
enter the radius of a sphere 3
The volume of the cylinder with
radius 3 and height 4 is 113.04
cubic units.
The volume of the sphere with
radius 3 is 113.04 cubic units.
#program 5
#to check biggest number among them
num1=int(input("enter the number 1"))
num2=int(input("enter the number 2"))
num3=int(input("enter the number 3")) enter the number 1: 4
if num1 >= num2 and num1 >= num3: enter the number 2: 67
biggest = num1
enter the number 3: 72
elif num2 >= num1 and num2 >= num3:
The biggest number among 4, 67,
biggest = num2 and 72 is 72.
else:
biggest =num3
print(f"The biggest number among {num1}, {num2}, and {num3} is {biggest}.")

#program 7
#to calculate the roots of quadratic eq ax^2+bx+c=0
a=int(input("enter cofficent of x^2"))
b=int(input("enter cofficent of x"))
c=int(input("enter constant term"))
# Calculate the discriminant
discriminant = b**2 - 4*a*c
# Calculate the roots OUTPUT
if discriminant > 0: enter cofficent of x^2 2
root1 = (-b + discriminant**0.5) / (2*a) enter cofficent of x 6
root2 = (-b - discriminant**0.5) / (2*a)
enter constant term 4
print(f"The roots are real and different: {root1} and {root2}")
The roots are real and different: -
elif discriminant == 0: 1.0 and -2.0
root1 = root2 = -b / (2*a)
print(f"The roots are real and the same: {root1} and {root2}")
else:
real_part = -b / (2*a)
imaginary_part = (-discriminant)**0.5 / (2*a)
print(f"The roots are complex: {real_part} + {imaginary_part}i and {real_part} - {imaginary_part}i")
#to find weather a number is a prime or not
a=int(input("enter a number ")) OUTPUT
if a==1:
enter a number 4
print("it is not a prime ")
it is not a prime number
if a>1:
enter a number 47
for i in range(2,a):
it is a prime number
if a%i==0:
print ("it is not a prime number")
break
else:
print("it is a prime number ")

# to find the prime number in a given range


for i in range(1,100):
if i>1: OUTPUT
for j in range(2,i): 2 3 5 7 11 13 17 19 23 29 31 37 41
if (i%j)==0: 43 47 53 59 61 67 71 73 79 83 89
97
break
else:
print(i,end=" ")
#to find the factorial of a nummber
number=int(input("enter a number ")) OUTPUT
fact=1 enter a number 5
a=1 the factorial of a given number 5
while(a<=number): is 120
fact=fact*a
a=a+1
print("the factorial of a given number" ,number, "is", fact)

#to calculate the sum of digits


n=int(input("enter a number"))
sum=0 OUTPUT

while(n>0): enter a TWO DIGIT number : 23456677

sum=sum+n%10 40

n=n//10
print(sum)

# to calcutale the reverse of a given nimber


n=int(input("enter a number:"))
OUTPUT
rev=0
while(n>0): enter a number: 4445567
rev=(rev*10)+n%10 the reverse of a given is
n=n//10 7655444
print("the reverse of a given is",rev)
#to write the palindrom of trhe given number
N=int(input(" enter any digit number: "))
rev=0
temp=N
while temp>0: OUTPUT
digit=temp%10
enter any digit number: 344556789
rev=(rev*10)+digit
it is not palindrome
temp=temp//10
enter any digit number: 1331
if (N==rev):
it is palindrone
print("it is palindrone")
else:
print("it is not palindrone")

#program to check weather a number is amstrong nummber or not


number=int(input("enter a number"))
sum=0
temp=number
while(temp>0): OUTPUT
digit=temp%10 enter a number 343
cube=digit**3
it is a not armstrong number
sum=sum+cube
temp//=10
enter a number 153
if(number==sum): it is a armstrong number
print("it is a armstrong number")
else:
print("it is a not armstrong number")
# to find the HCF AND LCM OF THR GIVEN NUMBER
a=int(input(" enter a number"))
b=int(input(" enter a number"))
if a>b:
OUTPUT
smaller=b
enter a number 12
else:
smaller=a
enter a number24
for i in range(1,smaller+1): The HCFs of them given number is
if((b%i==0) or(b%i==0)): 12
hcf=i the LCM of the given no is 24.0
lcm=(a*b)/hcf
print("The HCFs of them given number is",hcf)
print("the LCM of the given no is",lcm)

You might also like