BSC Cs Pratical
BSC Cs Pratical
def calculator():
c='y'
while(c=="y"):
print("\n\t\t*********----------CALCULATOR M E N U----------****************")
print("7 : EXIT")
if (choice==1):
add=a+b
elif(choice==2):
sub=a-b
elif(choice==3):
div=a/b
print('The division of',a,'and',b,'is :',div)
elif(choice==4):
mult=a*b
elif(choice==5):
rem=a%b
elif(choice==6):
squ=a**b
elif(choice==7):
break
else:
c=input("Press y to continue...:")
calculator()
Q2 A.
def star():
for j in range(1,i+1):
print(' * ',end='')
print()
star()
Q2 B.
#Q.2 ,b Dollor
def dollor():
n=5
print("$ $ $ $ $")
for j in range(1,i-2):
print('$ $' )
print("$ $ $ $ $")
dollor()
OUTPUT of 2 A and B
Q3.
# Solve the quadratic equation ax**2 + bx + c = 0
#Formula=x={-b+-[sqrt b**2-(4*a*c)]/(2*a)}
import math
def Quadratic():
if d<0:
elif (d>0):
sol1 = -b + d2/(2*a)
sol2= -b - d2/(2*a)
else:
print(sol1)
Q.4
#Table of sins,cosines&tangents,with given range 0 to 360 step of 45
import math
def Trigo():
i=0
n=360
for i in range (0,n+1,45) :
print(i)
a = math.sin(i)
b =math.cos(i)
c =math.tan(i)
Trigo()
Output 4
Q,5
#Menu driven program to calculate the Area...
def Menu( ):
c="yes"
while (c=="yes"):
print("4:Area of a TRIANGLE")
print("5:Exit")
if (choice==1):
area=side*side
elif(choice==2):
area=length*width
elif(choice==3):
area=3.14*radius**2
elif(choice==4):
area=1/2*length*base
break
else:
Menu()
Output 5
Q6
#6.Program to find nth terms of sum of series by computing with factorial function
if n==1:
return n
else:
return n*r_fact(n-1)
if num<0:
elif num==0:
else:
Sum=1
for i in range(1,n+1):
else:
output 6
Q7.
#Both iterative and recursive function of Fibonacii Sequence
a, b = 0, 1
if n<= 0:
elif n == 1:
else:
print(a)
print(b)
for i in range(2,n):
c=a+b
a=b
b=c
print(c)
if n<=1:
return n
else:
return(recur_fibo(n-1) + recur_fibo(n-2))
print (recur_fibo(i))
output 7..
Q8.
#Program to reverse a given number & compute the Sum of digit
def rev_number():
s=0
while (True):
k = str(n)
if k == k[ : :-1]:
break
else:
m = int(k[: :-1])
n2= m+n
s += 1
break
OUTPUT 8
Q9.
#Program to Find the LCM of two given no.
def lcm(n1,n2):
Max=n1
else:
Max =n2
if (Max%n1==0) and (Max%n2==0): # checking if Max is div by n1&n2 (To get remainder
0)
lcm=Max
break
Max+=1
def main():
main()
Output 9
Q10..
def prime(a):
lower=2
if num > 1:
for i in range(2,num):
if (num % i) == 0:
break
else:
def main():
for i in range(2,a):
if (a% i) == 0:
break
else:
if (a==1):
else:
a=prime(a)
main()
Output 10