[go: up one dir, main page]

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

Computer Science Record Programs

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 9

Program1

a=int(input("enter a number "))


b=int(input("enter another number "))
print (a, '+', b, '=' ,a+b)
print (a ,'-' ,b ,'=', a-b)
print (a, '*' ,b, '=', a*b)
print (a, '/', b ,'=' ,a/b)

OUTPUT

enter a number 2
enter another number 2
2+2=4
2-2=0
2*2=4
2 / 2 = 1.0

Program2

a=int(input("enter the principle amount "))


b=int(input("enter the duration "))
c=int(input("enter the rate of interest "))
p=(a*b*c)/100
print ('the simple interest is ', p)

OUTPUT

enter the principle amount 20


enter the duration 2
enter the rate of interest 20
the simple interest is 8.0

Program3

a=int(input("enter the temperature in fahrenheit "))


b=(a-32)*5/9
print ("the entered temperature in celsius is ",b)

OUTPUT

enter the temperature in fahrenheit 32


the entered temperature in celsius is 0.0
Program4

a=int(input("enter a 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 greatest number out of the three")
elif b>a and b>c:
print (b, " is the greatest number out of the three")
else:
print (c,' is the greatest number out of the three')

OUTPUT

enter a number4
enter the second number 2
enter the third number 6
6 is the greatest number out of the three

Program5

a=int(input("enter mathematics marks "))


b=int(input("enter physics marks "))
c=int(input("enter chemistry marks "))
d=int(input("enter english marks "))
e=int(input("enter computer science marks "))
avg=(a+b+c+d+e)/5
print ("average score is ",avg)
if avg>=90 and avg<=100:
print ("grade = A")
elif avg>=80 and avg<=89:
print ("grade = B")
elif avg>=70 and avg<=79:
print ("grade = C")
elif avg>=60 and avg<=69:
print ("grade = D")
elif avg<=60 and avg<=0:
print ("grade = E")
else:
print ("enter valid scores")

OUTPUT:

enter mathematics marks 90


enter physics marks 80
enter chemistry marks 60
enter english marks 90
enter computer science marks 90
average score is 82.0
grade = B

Program 6

fact=1
a=int(input("enter a number "))
for i in range (1,a+1):
fact=fact*i
print ("factorial of the entered number is ",fact)

OUTPUT

enter a number 3
factorial of the entered number is 6

Program 7

a=int(input("enter the number of terms "))


f=0
s=1
print (f)
print (s)
for i in range (a-2):
t=f+s
print(t)
f=s
s=t
print()

OUTPUT

enter the number of terms 7


0
1
1
2
3
5
8
Program 8

n=int(input("enter a number "))


s=0
while n>0:
s=s+(n%10)
n=n//10
print (s)

OUTPUT:

enter a number 45
9

Program 9

d=0
n=int(input("enter a number "))
l=len(str(n))
for i in range (l):
r=n%10
d=d*10+r
n=n//10
print (d)

OUTPUT:

enter a number 2468


8642

Program 10

d=0
n=int(input("enter a number "))
t=n
l=len(str(n))
for i in range (l):
r=n%10
d=d*r**l
n=n//10
if d==t:
print ("the entered number is an amstrong number ")
else:
print ("the entered number is not an amstrong number ")
OUTPUT:

enter a number 22
the entered number is not an amstrong number

Program 11

n=int(input("enter a number "))


s=0
for i in range (1,n):
if n%i==0:
s=s+i
if s==n:
print("the entered number is a perfect number ")
else:
print("the entered number is not a perfect number ")

OUTPUT:

enter a number 6
the entered number is a perfect number

Program 12

l=int(input("enter the lower range "))


u=int(input("enter the upper range "))
t=0
for x in range (l,u+1):
t=0
for i in range(2,x):
if x%i==0:
t=t+1
break
if t==0:
print(x)

OUTPUT

enter the lower range 4


enter the upper range 12
5
7
11
Program 13

a=input("enter a word ")


b=a[ : :-1]
if a==b:
print ("it is a palindrome")
else:
print ("it is not a palindrome")

OUTPUT

enter a word malayalam


it is a palindrome

Program 14

a=input("enter a word ")


lower=upper=digit=0
for i in a:
if i.isupper():
upper+=1
elif i.islower():
lower+=1
elif i.isdigit():
digit+=1
print ("number of uppercases = ",upper)
print ("number of lowercases = ",lower)
print ("number if digits = ",digit)

OUTPUT

enter a word HeLL0


number of uppercases = 3
number of lowercases = 1
number if digits = 1

Program 15

a=input("enter a word ")


print("length => ",len(a))
print("capitalize => ",a.capitalize())
print("count => ",a.count(a))
print("find => ",a.find('ab',3,6))
print("index => ",a.index('ab'))
print("isalnum => ",a.isalnum())
print("isalpha => ",a.isalpha())
print("isdigit => ",a.isdigit())
print("islower => ",a.islower())
print("isupper => ",a.isupper())
print("isspace => ",a.isspace())
print("lower => ",a.lower())
print("upper => ",a.upper())
print("startswith => ",a.startswith('ab'))
print("endswith => ",a.endswith('ab'))
print("title => ",a.title())
print("istitle => ",a.istitle())
print("replace => ",a.replace('ab','ob'))
print("join => ",'*'.join('hello'))
print("split => ",a.split('ab'))
print("partition => ",a.partition('ab'))
print("lstrip => ",a.lstrip())
print("rstrip => ",a.rstrip())
print("strip => ",a.strip())

OUTPUT

enter a word abcdefg


length => 7
capitalize => Abcdefg
count => 1
find => -1
index => 0
isalnum => True
isalpha => True
isdigit => False
islower => True
isupper => False
isspace => False
lower => abcdefg
upper => ABCDEFG
startswith => True
endswith => False
title => Abcdefg
istitle => False
replace => obcdefg
join => h*e*l*l*o
split => ['', 'cdefg']
partition => ('', 'ab', 'cdefg')
lstrip => abcdefg
rstrip => abcdefg
strip => abcdefg
Program 16

(i)
a=ord('A')
b=int(input("enter the number of rows: "))
for i in range(b):
for j in range (i+1):
print (chr(a+j),end='')
print ()

OUTPUT

enter the number of rows: 4


A
AB
ABC
ABCD

(ii)
a=int(input("enter the number of rows: "))
b=1
for i in range (a):
for j in range (i+1):
print(b,end='')
b=b+1
print()

OUTPUT

enter the number of rows: 4


1
23
456
78910

(iii)
a=int(input("enter the number of rows: "))
for i in range (a):
for j in range (i+1):
print ('*',end='')
print()
OUTPUT

enter the number of rows: 4


*
**
***
****

Program 17

You might also like