Вы находитесь на странице: 1из 11

Computer science

prograMMes
INPUT(PROGRAME
a=10

b=20

c=a+b

print("the sum is :",c)

OUTPUT

('the sum is :', 30)

INPUT

#programe to find a volume of the sphere

radius=float(input("write the radius of the sphere :"))

volume=4/3*3.14*radius**3

print("the volume of the sphere is :",volume)

OUTPUT

write the radius of the sphere :2.3

('the volume of the sphere is :', 38.20437999999999)

INPUT

#programe to find a exponent of a number

num1=int(input("please enter the base value :"))

num2=int(input("please enter the exponent value :"))

value=num1**num2

print("the exponent of a given number is :",value)


Computer science
prograMMes
OUTPUT

please enter the base value :25

please enter the exponent value :2

('the exponent of a given number is :', 625)

#Programe to find the distance travelled by a body during linear motion

U=float(input("please enter the initial velocity of a body :"))

T=float(input("please enter the time taken by a body :"))

A=float(input("please enter the acceleration of a body :"))

S=U*T+1/2*A*T**2

print("distance travelled by a body is :",S)

OUTPUT

please enter the initial velocity of a body :0

please enter the time taken by a body :2

please enter the acceleration of a body :2

('distance travelled by a body is :', 0.0)

INPUT

#programme to find a volume of a cylinder

radius=float(input("enter the radius of a cylinder :"))

height=float(input("enter the height of a cylinder :"))

print("radius of a cylinder is ",radius)


Computer science
prograMMes
print("height of a cylinder is ",height)

volume=3.14*radius**2*height

print("volume of a cylinder is :",volume)

OUTPUT

enter the radius of a cylinder :7

enter the height of a cylinder :1

('radius of a cylinder is ', 7.0)

('height of a cylinder is ', 1.0)

('volume of a cylinder is :', 153.86)

INPUT

#programme to find whether the number is divisible by 2

a=int(input("please enter the number :"))

if a%2==0:

print("number is divisible by 2")

OUTPUT

please enter the number :30

number is divisible by 2

INPUT

#programme to find whether the number is divisible by 2

a=int(input("please enter the number :"))

if a%2==0:

print("number is divisible by 2")


Computer science
prograMMes
else:

print("number is not divisible by 2")

OUTPUT

please enter the number :167

number is not divisible by 2

INPUT

#write a programe using if elif method

sales=float(input("please enter the total sales :"))

if sales>=3000:

amount=sales-sales*0.18

print("You have to pay :",amount)

elif sales>=2000:

amount=sales-sales*0.10

print("You have to pay :",amount)

else:

amount=sales-sales*0.05

print("you have to pay :",amount)

OUTPUT

please enter the total sales :2500

('You have to pay :', 2250.0)

INPUT
Computer science
prograMMes
#write a menu programe

print("MENU")

print("1.Area of a Circle")

print("2.Area of a Square")

print("3.Area of a Rectangle")

choice=int(input("please enter your choice either 1,2 or 3 :"))

if choice==1:

radius=float(input("please enter the radius of a circle :"))

area=3.14*radius**2

print("the area of a circle is :",area)

if choice==2:

side=float(input("please enter the side of a square :"))

area=side**2

print("the area of a square is :",area)

if choice==3:

length=float(input("please enter the length :"))

breadth=float(input("please enter the breadth :"))

area=length*breadth

print("the area of a rectangle is :",area)

OUTPUT

MENU

1.Area of a Circle
Computer science
prograMMes
2.Area of a Square

3.Area of a Rectangle

please enter your choice either 1,2 or 3 :2

please enter the side of a square :15

('the area of a square is :', 225.0)

INPUT

#wap to swap the number

a=int(input("enter the first number :"))

b=int(input("enter the second number :"))

print("first number is :",b,"second number is :",a)

OUTPUT

enter the first number :10

enter the second number :20

('first number is :', 20, 'second number is :', 10)

INPUT

#wap to find cube of first ten number using for loop

for a in range(1,11):

print("the cubes are :",a*a*a)

OUTPUT

('the cubes are :', 1)

('the cubes are :', 8)

('the cubes are :', 27)


Computer science
prograMMes
('the cubes are :', 64)

('the cubes are :', 125)

('the cubes are :', 216)

('the cubes are :', 343)

('the cubes are :', 512)

('the cubes are :', 729)

('the cubes are :', 1000)

INPUT

#wap to find squares of first five number using for loop

for a in range(1,6):

print("the squares are :",a*a)

OUTPUT

('the squares are :', 1)

('the squares are :', 4)

('the squares are :', 9)

('the squares are :', 16)

('the squares are :', 25)

INPUT

#wap to find the squares of first 10 natural numbers using while loop

a=0

while(a<=9):

a=a+1
Computer science
prograMMes
print("the squares are :",a*a)

OUTPUT

('the squares are :', 1)

('the squares are :', 4)

('the squares are :', 9)

('the squares are :', 16)

('the squares are :', 25)

('the squares are :', 36)

('the squares are :', 49)

('the squares are :', 64)

('the squares are :', 81)

('the squares are :', 100)

INPUT
#write a programme to find the cubes of first 10 natural numbers

a=0

while(a<=9):

a=a+1

print("the cubes are :",a*a*a)

OUTPUT

('the cubes are :', 1)

('the cubes are :', 8)

('the cubes are :', 27)


Computer science
prograMMes
('the cubes are :', 64)

('the cubes are :', 125)

('the cubes are :', 216)

('the cubes are :', 343)

('the cubes are :', 512)

('the cubes are :', 729)

('the cubes are :', 1000)

INPUT

#wap to find the factorial of a number

fact=1

for a in range(1,6):

fact=fact*a

print("the factorial is :",fact)

OUTPUT

('the factorial is :', 1)

('the factorial is :', 2)

('the factorial is :', 6)

('the factorial is :', 24)

('the factorial is :', 120)

INPUT

#wap to find factorial

fact=1
Computer science
prograMMes
for a in range(1,10):

fact=fact*a

print("the factorial is :",fact)

OUTPUT

('the factorial is :', 1)

('the factorial is :', 2)

('the factorial is :', 6)

('the factorial is :', 24)

('the factorial is :', 120)

('the factorial is :', 720)

('the factorial is :', 5040)

('the factorial is :', 40320)

('the factorial is :', 362880)

INPUT

#wap to find the sum of first 10 natural numbers

sum=0

for a in range(1,11):

sum=sum+a

print("the sum is :",sum)

OUTPUT

('the sum is :', 1)

('the sum is :', 3)


Computer science
prograMMes
('the sum is :', 6)

('the sum is :', 10)

('the sum is :', 15)

('the sum is :', 21)

('the sum is :', 28)

('the sum is :', 36)

('the sum is :', 45)

('the sum is :', 55)

Вам также может понравиться