Cs Rishav
Cs Rishav
first=0
second=1
num=int(input("how many Fibonacci numbers you want to display : "))
if num<=0:
print("Please Enter positive Integer ")
else:
print(first,end=" ")
print(second,end=" ")
for i in range(2,num):
third=first+second
first=second
second=third
print(third, end=" ")
f.close()
print("The total numbers of vowels in the file : ",vowels)
print("The total numbers of consonants in the file : ",consonants)
print("The total numbers of lowercase in the file : ",lowercase)
print("The total numbers of uppercase in the file : ",uppercase)
The total numbers of vowels in the file : 19
The total numbers of consonants in the file : 41
The total numbers of lowercase in the file : 57
The total numbers of uppercase in the file : 3
'''WAP to read lines from a text file "sample.txt" and copy those lines
into another file which are starting
with an alphabet "a" or "A"'''
f1=open(r"C:\Users\RAA LAB\Desktop\story.txt","r")
f2=open(r"C:\Users\RAA LAB\Desktop\new.txt","w")
while True:
line=f1.readline()
if line == '':
break
if line[0]=='a' or line[0]=='A':
f2.write(line)
print("All lines which are starting with character 'a' or 'A' has been
copied\
successfully into new.txt")
f1.close()
f2.close()
All lines which are starting with character 'a' or 'A' has been copied
successfully into new.txt
'''Write a MENU driven program to find Factorial and sum of list of
numbers using list'''
def factorial(no):
f=1
if no<0:
print("Sorry, we cannot take factorial for a Negative Number ")
elif no==0:
print("The Factorial of 0 is 1")
else:
for i in range (1,no+1):
f=f*i
print("The Factorial os ",no,'is :',f)
def Sum_list(L):
sum=0
for i in range(n):
sum=sum+L[i]
print("The sum of List : ",sum)
#MAIN PROGRAM
1. To find Factorial
2. To find Sum of List Elements
Enter your Choice : 1
Enter a number to find Factorial : 6
The Factorial os 6 is : 720
1. To find Factorial
2. To find Sum of List Elements
Enter your Choice : 2
Enter how many elements you want to store in List? : 3
Enter n elements : 21
Enter n elements : 24
Enter n elements : 1
The sum of List : 46
‘’’Write a program to implement STACK operation’’’
def PUSH():
ele=int(input("Enter the element you want to push: "))
stack.append(ele)
def POP():
if stack==[]:
print("Stack is empty/underflow ")
else:
print("The deleted element is :",stack.pop())
def PEEK():
top=len(stack)-1
print("the top most element of stack is :stack[top]")
def DISPLAY():
top=len(stack)-1
print("The stack elements are :")
for i in range(top,-1,-1):
print(stack[i])
#main program
stack=[]
option='y'
while option=='y' or option == 'Y':
print("Stack operations ")
print("*********************")
print("1. PUSH")
print("2. POP")
print("3. PEEK")
print("4. DISPLAY")
print("*********************")
option=int(input("Enter Option or choice : "))
if option==1:
PUSH()
elif option==2:
POP()
elif option==3:
PEEK
elif option==4:
DISPLAY()
else:
print("Enter valid choice/option")
option=input("Do you want to perform another stack operation
(y/n) : ")
Stack operations
*********************
1. PUSH
2. POP
3. PEEK
4. DISPLAY
*********************
Enter Option or choice : 1
Enter the element you want to push: 56
Do you want to perform another stack operation (y/n) : y
Stack operations
*********************
1. PUSH
2. POP
3. PEEK
4. DISPLAY
*********************