PART-A python manual BCA.doc
PART-A python manual BCA.doc
[DATE]
[Company address]
1.check if a number belongs to the Fibonacci sequence
num=int(input("Enter the number you want to check\n"))
c=0
a=0
b=1
print("fibonnaci series:")
print(a)
if num==0 or num==1:
print("Yes")
else:
while c<num:
c=a+b
b=a
a=c
print(c)
if c==num:
print("Yes. {} is a fibonnaci number".format(num))
else:
print("no. {} is NOT a fibonnaci number".format(num))
output:
Enter the number you want to check
fibonnaci series:
output:
Enter a:10
Enter b:20
Enter c:30
-800.0
output:
Enter the number:5
The Sum is 1
The Sum is 3
The Sum is 6
The Sum is 10
The Sum is 15
output:
5. Check if a given number is a Prime Number or not
num=int(input('Enter the number:'))
if num < 0:
print('Enter a positive number')
else:
sum=(num*(num+1))/2
sum=0
i=1
print('The Natural numbers are:')
while(i<=num):
sum += i
print(i)
i = i+1
print('The Sum is',sum)
output:
Enter the number5
5 is a prime number
list1 = [1, 3, 5, 4, 7, 9]
key = 7
n = len(list1)
res = linear_Search(list1, n, key)
if (res == -1):
print("Element not found")
else:
print("Element found at index: ", res)
output:
Element found at index: 4
select=int(input("enter ur choice"))
if select==1:
print(num1,'+',num2,'=',num1+num2)
elif select==2:
print(num1,'-',num2,'=',num1-num2)
elif select==3:
print(num1,'*',num2,'=',num1*num2)
elif select==4:
print(num1,'/',num2,'=',num1/num2)
else:
print("invalid input")
output:
select the operation
enter ur choice1
22 + 55 = 77
Output:
Shree Medha
shree
MEDHA
Sh
Medh
45
Fort
ballari
r
e
Shree
-1
Ballari
Ballari
for i in range(9):
chk = 0
small = nums[i]
for j in range(i+1, 10):
if small > nums[j]:
small = nums[j]
chk = chk + 1
index = j
if chk != 0:
temp = nums[i]
nums[i] = small
nums[index] = temp
output:
Enter 10 Elements for the List:
5
6
print(my_stack)
Output:
['x', 'y', 'z']
[]
output: