12th CS Practical Manual-1
12th CS Practical Manual-1
Algorithm:
Step 1: Start a program
Step 2: Declare variable num, fact, i
Step 3: Use a while loop to multiply the number to the factorial variable and then increment
the number.
Step 4: Repeat until i<=num
4.1 fact=fact*i
4.2 i=i+1
Step 5: Print the factorial of the number
Step 6 : Exit
Source Code:
Output:
Result :
Thus the above program is executed and output is verified successfully.
Program 2: Write a Program to enter the number of terms and to print the Fibonacci Series.
Output:
Program 3: Input any number from user and check it is Prime no.
or not
#Program to input any number from user
#Check it is Prime number of not
import math
num = int(input("Enter any number :"))
isPrime=True
for i in range(2,int(math.sqrt(num))+1):
if num % i == 0:
isPrime=False
if isPrime:
print("## Number is Prime ##")
else:
print("## Number is not Prime ##")
OUTPUT
Enter any number :117
## Number is not Prime ##
>>>
Enter any number :119
## Number is not Prime ##
>>>
Enter any number :113
## Number is Prime ##
>>>
Enter any number :7
## Number is Prime ##
>>>
Enter any number :19
## Number is Prime ##
Page :
filein = open("Mydoc.txt",'r')
for line in filein:
word= line .split()
for w in word:
print(w + '#',end ='')
print()
filein.close()
output:
s = str1.split()
count=0
for w in s:
if w==word:
count+=1
return count
count = countWord(str1,word)
if count==0:
else:
Output:
Enter any sentence :'my computer your computer our computer everyones
computer'
>>>
>>>
Program :7 Create a binary file with name and roll number of the students.
Search for a given roll number and display the name of student.
Output:
Program : 8Write a program to calculate compound
interest.
Source Code:
Output:
>>>
var=False
Output:
class Stack:
def __init__(self):
self.items = [ ]
def size(self): # Size of the stack i.e. total no. of elements in stack
return len(self.items)
s = Stack( )
print("MENU BASED STACK")
cd=True
while cd:
print(" 1. Push ")
print(" 2. Pop ")
print(" 3. Display ")
print(" 4. Size of Stack ")
print(" 5. Value at Top ")
choice=int(input("Enter your choice (1-5) : "))
if choice==1:
val=input("Enter the element: ")
s.push(val)
elif choice==2:
if s.items==[ ]:
print("Stack is empty")
else:
print("Deleted element is :", s.pop( ))
elif choice==3:
print(s.items)
elif choice==4:
print("Size of the stack is :", s.size( ))
elif choice==5:
print("Value of top element is :", s.peek( ))
else:
print("You enetered wrong choice ")
print("Do you want to continue? Y/N")
option=input( )
if option=='y' or option=='Y':
var=True
else:
var=False
Output:
MENU BASED STACK
1. Push
2. Pop
3. Display
4. Size of Stack
5. Value at Top
Enter your choice (1-5) : 1
Enter the element: 45
Do you want to continue? Y/N
y
1. Push
2. Pop
3. Display
4. Size of Stack
5. Value at Top
Enter your choice (1-5) : 3
['45']
Do you want to continue? Y/N
y
1. Push
2. Pop
3. Display
4. Size of Stack
5. Value at Top
else:
myd[w]+=1
key_max = max(myd,key=myd.get)
print("Most Common Occuring word is :",key_max)
OUTPUT
Most Common Occuring word is : mymoney.com
OUTPUT:
Enter Employee Number 1
Enter Employee Name Amit
Enter Employee Salary :90000
## Data Saved... ##
Add More ?y
Enter Employee Number 2
Enter Employee Name Sunil
Enter Employee Salary :80000
## Data Saved... ##
Add More ?y
Enter Employee Number 3
Enter Employee Name Satya
Enter Employee Salary :75000
## Data Saved... ##
Add More ?n
Enter Employee Number to search :2
============================
NAME : Sunil
SALARY : 80000
Search More ? (Y)y
Enter Employee Number to search :3
============================
NAME : Satya
SALARY : 75000
Search More ? (Y)y
Enter Employee Number to search :4
==========================
EMPNO NOT FOUND
==========================
Search More ? (Y)n
Program 13- A list Num contains the following elements: 3, 21, 5, 6, 14, 8, 14, 3 WAP to swap the
content with next value divisible by 7 so that the resultant array will look like: 3, 5, 21, 6, 8, 14, 3, 14
OUTPUT:
Source Code:
import numpy as np
number_month = years * 12
PROGRAM:15: Write a program to perform read and write operation with .csv file.
SOURCE CODE:
import csv
def readcsv():
with open('C:\\Users\\ViNi\\Downloads\\data.csv','rt')as f:
print(row)
def writecsv( ):
a=int(input())
if a==1:
readcsv()
elif a==2:
writecsv()
else:
print("Invalid value")
OUTPUT:
Press-1 to Read Data and Press-2 to Write data: