Cs File Kchi - Merged
Cs File Kchi - Merged
PRACTICAL NO-1
CREATING A PYTHON PROGRAM TO GENERATE RANDOM
BETWEEN 1 TO 6
AIM :
To write a python program to generate random number between 1 ton
6 to simulate dice.
SOURCE CODE :
... no=random.randint(1,6)
... if Choice=='y':
... else:
... break
RESULT :
Thus, the above python program has been executed and the
output is verified successfully.
SAMPLE OUTPUT :
PYTHON EXECUTED OUTPUT PROGRAM :
PRACTICAL NO- 2
SOURCE CODE :
>>> f=open(“story.txt”,’r’)
>>> Contents=f.readlines()
... words=line.spilt()
... print(i+’#’,end=’ ‘)
... print(“ “)
>>> f.close()
RESULT :
Thus, the above Python program has been executed and the
output is verified successfully
SAMPLE OUTPUT :
STORY.TXT :
DATE :
PRACTICAL NO- 3
SOURCE CODE :
>>> f=open("story.txt",'r')
>>> Content=f.read()
>>> Vowels=0
>>> Consolants=0
>>> Lower_case=0
>>> Upper_case=0
... if ch in'aeiouAEIOU':
... Vowels=Vowels+1
... if ch in'bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ':
... Consolants=Consolants+1
... if ch.islower():
... Lower_case=Lower_case+1
... if ch.isupper():
... Upper_case=Upper_case+1
>>> f.close()
RESULT :
SAMPLE OUTPUT :
STORY.TXT:
DATE :
PRACTICAL NO- 4
... F=open("poem.txt")
... S=F.read()
... W=S.spilt()
... for i in W:
... if len(i)<5:
... print(i,end='')
... F.close()
>>> Disp()
RESULT :
Thus, the above Python program has been executed and the
output is verified successfully.
SAMPLE OUTPUT :
POEM.TXT
DATE :
PRACTICAL NO – 5
CREATING A PYTHON PROGRAM TO CREATE AND UPDATE/MODIFY
AIM :
To write a Python Program to Create a binary file with roll number,
name, mark and update/modify the mark for a given roll number
SOURCE CODE :
Type "help", "copyright", "credits" or "license()" for more
information. import pickle
def Create():
F=open("Students.dat",'a
b') opt='y'
while opt=='y':
Roll_No=int(input('Enter roll
number:')) Name=input("Enter
Name:") L=[Roll_No,Name]
pickle.dump(L,F)
...
... F=open("Students.dat",'rb')
... found=0
... try:
... S=pickle.load(F)
... if S[0]==no:
... found=1
... break
... except:
... F.close()
...
...
... F=open("Students.dat",'rb')
... found=0
... try:
... S=pickle.load(F)
... if S[0]==no:
... found=1
... break
... except:
... F.close()
... if found==0 :
... Create()
... Update()
RESULT :
Thus, the above Python program has been executed and the
output is verified successfully.
SAMPLE OUTPUT :
PYTHON PROGRAM EXECUTED OUTPUT :
PRACTICAL NO: 6
AIM: To write a menu driven Python Program to perform Arithmetic operations (+,-*,/)
based on the user’s choice.
SOURCE CODE:
print("1. Adddition")
print("2. Subtraction")
print("3.
Multiplication")
print("4. Division")
opt=int(input("Enter your choice:"))
a=int(input("Enter the First Number:"))
b=int(input("Enter the Second
Number:")) if opt==1:
c=a+b
else:
else:
c=a/b
print("Invalid Option")
Result:
Thus, the above Python program has been executed and the output is verified successfully.
Sample Output:
• Subtr
action
• Multiplication
• Division
Enter your
choice:3
PRACTICAL NO: 7
DATE:
SOURCE CODE:
First=0
Second
=1
no=int(input("How many Fibonacci numbers you want
to display?")) if no<=0:
print("Please Enter Positive Integer")
else:
Result:
Thus, the above Python program has been executed and the output is verified successfully.
SAMPLE OUTPUT:
3
PRACTICAL NO: 8
DATE:
AIM: To write a menu driven Python Program to find Factorial and sum of list of numbers
using function.
SOURCE
CODE:
def Factorial(no):
F=1
if no<0:
else:
for i in
range(1,no+1)
: F=F*i
print("The Factorial of", no, "is:",F)
def Sum_List(L):
Sum=0
for i in range(n):
Sum=Sum+L[i]
L=[]
Result:
Thus, the above Python program has been executed and the output is verified successfully.
Sample Output:
• To Find Factorial
• To Find sum of
List elements Enter your
choice:1
Enter a number to find
Factorial:7 The Factorial of 7 is:
5040
Practical No:9
DATE:
AIM: To Write a Python program to define the function Check(no1,no2) that take two numbers
and Returns the number that has minimum ones digit.
Source Code:
def Check(no1,no2):
if (no1%10) <
(no2%10): return
no1
else:
return no2
r=Check(a,b)
Result:
Thus, the above Python program has been executed and the output is verified successfully.
Sample Output:
Source Code:
import math
def Square(num):
S=math.pow(num,
2) return S
def Log(num):
S=math.log10
(num) return S
def Quad(X,Y):
S=math.sqrt (X**2 +
Y**2) return S
print("The Square of a Number is:", Square
(7)) print("The Log of a Number is:", Log
(100)) print("The Quad of a Number
is:", Quad (2,2))
Result:
Thus, the above Python program has been executed and the output is verified successfully.
Sample Output: