Python Manual
Python Manual
outputs:
1. Check if a number belongs to the Fibonacci Sequence.
def checkFibonacci(n):
a=0
b=1
if (n==a or n==b):
return True
c = a+b;
while(c<=n):
if(c == n):
return True
a=b
b=c
c=a+b
return False
dis = (b * b) - (4 * a * c)
ulist = []
n = int(input("Enter number of elements: "))
print("Enter the elements: ")
for i in range(0,n):
ulist.append((input()).lower())
#Searches the string for a specified value and returns the position of where it
was found
str2 = (input("Enter the item to be found in specified string: ")).lower()
pos = strlow.find(str2)
if pos == -1:
print("item not found")
else:
print(pos)
data = []
size = int(input("Enter the size of array: "))
print("Enter the elemenst: ")
for i in range(0,size):
data.append(int(input()))
selectionSort(data, size)
print('Sorted Array in Ascending Order:')
print(data)
10. outputs:
10. Implement stack
stack = []
while True:
choice = int(input("1.Push\n2.Pop\n3.Display\n4.Exit\nEnter your choice: "))
if(choice == 1):
# append() function to push
stack.append(input("Enter item to push: "))
elif (choice == 2):
stack.pop()
elif (choice == 3):
print(stack)
else:
exit()
11. outputs:
11. Read and write into a file