[go: up one dir, main page]

0% found this document useful (0 votes)
21 views16 pages

Class 11 Computer Science

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 16

1.

SIMPLE INTEREST AND COMPOUND INTEREST


p=float(input("enter the principal"))
n=int(input("enter the no of years"))
r=float(input("enter the rate of inperest"))
si=p*n*r/100
ci=p*(pow(1+r/100,n)-1)
print("simple intrest",si)
print("compound interest",ci)

TEMPERATURE CONVERSION
print("temperature in conversion")
c=float(input("enter the temperature in clesius"))
f=(c*9/5)+35
print("equivalent in fahrenhiet",f)
print("distance-inches to feet and inches")
inches=int(input("enter the distance in iches"))
feet=inches/12
inches=inches%12
print("feet",feet)
print("inches",inches)
SUM OF SERIES
x=int(input("Enter the value of x:"))
n=int(input("Enter the power (n):"))
s=x
sign=+1
for a in range(2,n+1):
f=1
for i in range(1,a+1):
f*=i
term=((x**a)*sign)/f
s+=term
sign*=-1
print("Sumof first",n,"terms:",s)
ARMSTRONG NUMBER
num=int(input("enter a three digit number:"))
summ=0
temp=num
while(temp>0):
digit=temp%10
summ=digit**3
temp//=10
if(num==summ):
print(num,"it is an amstrong number")
else:
print(num,"is not an amstrong number")

PALINDROME
num=int(input("enter number"))
wnum=num#working number stores num initially
rev=0
while(wnum>0):
dig=wnum%10
rev=rev*10+dig
wnum=wnum/10
if(num==rev):
print("number",num,"palindrome!")
else:
print("number",num,"not a palindrome!")

GREATEST OF 3 NUMBERS
print("enter the number")
a=int(input("a"))
b=int(input("b"))
c=int(input("c"))
if(a>b):
if(a>c):
print(a,"is the greast of three numbers")
else:
print(c,"is the greast of three numbers")
else:
if(b>c):
print(b,"is the greast of three numbers")
else:
print(c,"is the greast of three numbers")

ELECTRICITY BILL CALCULATION


units=int(input("enter the units consumed"))
if(units<=50):
amt=0.0
elif(units>=51 and units<=100):
amt=units*0.60
elif(units>=101 and units<=200):
amt=units*0.75
elif(units>=201 and units<=300):
amt=units*0.90
else:
amt=units*1.15
print("for the",units,"units you have to pay:",amt)

TRIANGLE PATTERN - 1
ch=0
while(ch!=3):
print("\n 1.horizontal\n 2.alphabet(right to left)\n
3.exit")
ch=int(input("enter your choice"))
if(ch==1):
n=int(input("enter the number of stages:"))
for i in range(1,n+1):
for j in range (1,n+1):
print(i,end=" ")
print()
elif(ch==2):
n=int(input("enter the number of rows:"))
for i in range(n):
c=65
for k in range(i,n-1):
print(end=" ")
for j in range(i+1):
print(chr(c),end=" ")
c=c+1
print()
elif(ch==3):
print("thank you")
else:
print("enter a valid choice")

TRIANGLE PATTERN - 2
ch=0
while(ch!=3):
print("\n1 .pyramid \n2 . inverted hollow pyramid \
n3.exit")
ch=int(input("enter your choice:"))
if(ch==1):
n=int(input("enter the number of steps:"))
for i in range (1,n+1):
for k in range(i,n):
print(end=" ")
for j in range(2*i+1):
print("*",end=" ")
print( )
elif(ch==2):
n=int(input("enter the number of steps:"))
for i in range (n,0,-1):
for j in range (n-i):
print(' ',end=" ")
for j in range (2*i-1):
if(i==0 or j==2*i-2 or i==n or j==0):
print("*",end=" ")
else:
print(' ',end=" ")
print( )
elif(ch==3):
print("thank you")
else:
print("enter a valid option")

STRING -1
STRING - 2
a=input("enter a string")
w=1
v=0
u=0
d=0
s=0
v1=("aeiouAEIOU")
for b in range(len(a)):
if(a[b]>="0" and a[b]<="9"):
d=d+1
elif(a[b]>="a" and a[b]>="z" or a[b]>="A" and
a[b]>="Z"):
if(a[b]>="A" and a[b]>="Z"):
d=d+1
if(a[b] in v1):
v=v+1
elif (a[b]==(' ')):
w=w+1
else:
s=s+1
print("no of word",w)
print("no of vowels",v)
print("no of digit",d)
print("no of word",w)

LIST OPERATION - 1
n=int(input("enter the no.of elements:"))
oned_list=[0 for size in range(n+1)]
print("Enter the input values:")
for size in range(n):
x=int(input("enter the no:"))
oned_list[size]=x
print()
print("user entered values:")
for size in range(n):
print(oned_list[size],end =" ")
print()
e=int(input("enter the element to be inserted"))
x=int(input("enter the position to be inserted"))
for i in range(n):
if(x-1==i):
for j in range(n,i-1,-1):
oned_list[j]=oned_list[j-1]
oned_list[i]=e
n=n+1
break
print()
print("new array after insertion")
for size in range(n):
print(oned_list[size],end=" ")
print()
x=int(input("enter the no.to be deleted:"))
for i in range(n):
if(x==oned_list[i]):
print(oned_list[i],"deleted")
s=i
for j in range(s,n-1):
oned_list[j]=oned_list[j-i]
n=n-1
print("list of elememts after deletion")
for size in range(n-1):
print(oned_list[size])

LIST OPERATION - 2
n=int(input("enter the no.of elements:"))
l=[]
for i in range (n):
x=int(input("enter the elements:"))
list.insert(l,i,x)
ch=0
while(ch!=4):
print("\n1.max/n2.min\n3.exit")
ch=int(input("enter your choice:"))
if(ch==1):
maxi=l[0]
for i in range(1,n):
if maxi < l[i]:
maxi=l[i]
print("the maximum elements in the list", maxi)
elif(ch==2):
mini=l[0]
for i in range (1,n):
if mini >l[i]:
mini=l[i]
print ("the minimum elements in the ",mini)
elif (ch==3):
print("thank you")
else:
print("enter a valid choice")

LIST OPERATION - 3
l=[]
n=int(input("enter the value of n:"))
for i in range(n):
x=int( input("enter the number:"))
list. insert(l,i,x)
ch=0
while(ch!=3):
print("\n1.ascending\n2.descending\n3.exit")
ch=int(input("enter the choice:"))
if(ch==1):
for i in range(n):
for j in range(i+1,n):
if(l[i]>l[j]
t=l[i]
l[i]=l[j]
l[j]=t
print("the sorted list -ascending order:")
for i in range (n):
for j in range (i-1,n):
if(l[i]<l[j]):
t-l[i]
l[i]=l[j]
l[j]=t
print("the stored list-descending order:")
for i range (n):
print([i],end="")
elif(ch==3):
print("thank you")
else:
print("enter a valid choice:")
LIST OPERATION - 4
print("enter the no of rows and colums for matrix A")
r1=int(input("enter the no of rows"))
c1=int(input("enter the no of colums"))
A=[[0 for col in range(c1)] for row in range(r1)]
print("enter the value of A Matrix:")
for i in range(r1):
for j in range(c1):
x=int(input("enter a no"))
A[i][j]=x
print("enter the no of rows and colums for matrix")
r2=int(input("enter a number of rows"))
c2=int(input("enter the number of colums"))
B=[[0 for col in range(c2)] for row in range(r2)]
print("enter the values of B matrix")
for i in range(c2):
for j in range(c2):
x=int(input("enter a number"))
B[i][j]=x
if(r1==r2 and c1==c2):
print("sum of matrix A and sum of Matrix")
for i in range(r1):
for j in range(c2):
print(A[i][j]+B[i][j],end=" ")
print(" ")
else:
print("matrix addition is not possible")
LIST OPERATION - 5
rn =int(input("enter the no.of rows"))
cn=int(input("enter the no.of coloumns"))
A=[[0 for col in range (cn)] for row in range (rn)]
for i in range (rn):
for j in range(cn):
x=int(input("enter the no"))
A[i] [j]=x
print("the given matrix is")
for i in range (rn):
for j in range (cn):
print(A[i][j], end=" ")
print(" ")
print("\n.upper half elements")
for row in range (rn):
for col in range (cn):
if (row <=col):
print(A[row] [col], end= " ")
else:
print (end= " ")
print (" ")
print ("\n diagonal elements ")
for i in range (rn):
for j in range (cn):
if(i==j or i+j==rn-1):
print (A [i] [j],end= " ")
else:
print (end= " ")
print(" ")
print ("\n coloumn elements:")
for i in range (rn):
for j in range (cn):
print (A [i] [j] , end ="\t")
print (" ")
cols=[0 for col in range (cn)]
for i in range (cn):
for j in range (rn):
cols[i]+=A[j] [i]
print("_________________")
for i in range(cn):
print(cols[i], end="\t")
print()
print("_________________")

TUPLE OPERATION
tup1=eval(input("enter few over score:"))
ch=0
while(ch!=6):
print("\n1.length of the tuple\n2.slicing\
n3.concantenation\n4.membership operator\n5.count\
n6.exit")
ch=int(input("enter your choice"))
if(ch==1):
print("no.of over:",len(tup1))
elif(ch==2):
print("enter the starting and the ending over:")
s,e=int(input()),int(input())
print("slicing of score card:")
print(tup1[s-1:e])
elif(ch==3):
tup2=eval(input("enter few more over score:"))
tup1=tup1+tup2
print("new score card:",tup1)
x=int(input("enter the runs to be searched:"))
if x in tup1:
print("runs present in the over:",tup1.index(x)+1)
else:
print("runs not present in the scorecard")
print("IT NOT IN operator")
print("runs in the scorecard:",tup1)
if x not in tup1:
print("runs not present in the scorecard")
else:
print("runs present in the over",tup1.index(x)
+1)
elif(ch==5):
print("elements in tup1:",tup1)
x=int(input("enter the runs:"))
print(x,"runs present in the
scorecard",tup1.count(x),"times(s)")
elif(ch==6):
print("thank you")

DICT OPERATION - 1
prod=dict()
n=int(input("enter the no.of products"))
i=1
while(i<=n):
pname=input("enter the products")
pri=float(input("enter the price"))
prod[pname]=pri
i=i+1
ch=0
while ch!=5:
print("\n1.append\n2.update\n3.delete\n4.display all\
n5.exit")
ch=int(input("enter your choice"))
if(ch==1):
pname=input("enter the new product name")
pri=float(input("enter the price"))
prod[pname]=pri
print("\n\t product appended successfuly")
elif(ch==2):
upn=input("enter the product name to be update")
if upn in prod:
npr=float(input("enter the new price"))
prod[upn]=npr
print("\n\t product price update")
else:
print("product doen't exit")
elif(ch==3):
upn=input("enter the products name to be delete")
if upn in prod:
print(upn,end="")
print(prod.pop(upn),end="")
print("\t product does't exit")
else:
print("product does't exit")
elif(ch==4):
print("\n product name\t price")
for i in prod:
print(i,"\t",prod[i])
elif(ch==5):
print("thank you")
else:
print("enter a valid choice")

DICT OPERATION - 2
stu=dict( )
ch=0
while ch!=6:
print("\n\n\t\t****student detail system****")
print("1.add new\n2.search\n3.pop\n4.display\
n5.clean all\n6.exit")
ch=int(input("enter your choice"))
if (ch==1):
stid=int (input(" enter the student id:"))
n=input("enter the student name:")
m=float (input("enter the average marks:"))
g=input ("enter the grade")
stu [stid]=(n,m,g)
elif (ch==2):
sid=int(input("enter the student id for
searching"))
if sid in stu:
print ("name,marks,grads")
print (stu.get (sid))
else:
print ("student not in the list")
elif (ch==3):
sid=int(input ("enter the student id for
deleting"))
if sid in stu:
del stu [sid]
print("record deleted")
else:
print ("student not in the list")
elif(ch==4):
for i in stu:
print(i,end="\t")
t=stu[i]
for j in t:
print(j,end="\t")
print()
print("\n total student:",len(stop))
elif(ch==5):
stu.clean()
print("all the records delected")
elif(ch==6):
print ("thank you")
else:
print("enter a valid choice")

DICT OPERATION - 3
book=dict()
ch=0
while ch!=6:
print("\n\n\n\t****Library management system****")
print("1.Addnew\n2.search\n3.pop\n4.check total
books\n5.clear\n6.exit")
ch=int(input("enter your choice"))
if(ch==1):
bid=int(input("enter your ISBN"))
n=input("enter the book name")
p=float(input("enter the price"))
y=int(input("enter the publication year"))
book[bid]=(n,y,p)
elif(ch==2):
bk=int(input("enter thr ISBN for searching"))
if bk in book:
print("name,price,year")
print(book.get(bk))
else:
print("ISBN not available")
elif(ch==3):
bk=int(input("enter the ISBN for deleting"))
if bk in book:
del book[bk]
print("record delting")
else:
print("ISBN not avabale")
elif(ch==4):
for i in book:
print(i,end="\t")
t=book[i]
for j in t:
print(j,end="\t")
print( )
print("\n total books:",len(book))
elif(ch==5):
book.clear()
print("all the reords deleted")
elif(ch==6):
print("thank you")
else:
print("enter the valid choice")

You might also like