Sunteți pe pagina 1din 5

CODE:

“Python program to count the words”


“Written by V.M.Pavithranathan(181001036)”
“Written on
import sys

if(len(sys.argv) < 1):


sys.exit()

inp = sys.argv[1]

words = inp.split()

no_of_words = len(words)
no_char = []
for word in words:
no_char.append(len(word))

tot_no_char = sum(no_char)

print("Output")
print("------")
print("The Input String is", inp)
print("Total number of Words is %i :" %(no_of_words))
print("Total number of Characters is %i :" %(tot_no_char))
for i in range(len(words)):
print("Total Characters in %s is %i" %(words[i],no_char[i]))

Output:
Output
------
The Input String is Vijay
Total number of Words is 1 :
Total number of Characters is 5 :
Total Characters in Vijay is 5
CODE:
“Python program to create scientific Calculator”
“Written by V.M.Pavithranathan(181001036)
import sys
import math

if(len(sys.argv) < 1):


sys.exit()
elif(len(sys.argv) == 3):
func = sys.argv[1]
var = int(sys.argv[2])
if (func == "sqrt"):
print("Square Root for the given number %i is %i" %(var,math.sqrt(var)))
elif (func == "sqr"):
print("Square for the given number %i is %i" %(var,var*var))
else:
if(sys.argv[1]=="pow"):
a =int( sys.argv[2])
b = int(sys.argv[3])
print("%d power %d is is %d" %(a,b, a**b))
sys.exit()
op1 =int(sys.argv[1])
op = sys.argv[2]
op2 = int(sys.argv[3])
if(op == '+'):
print("Sum of %i and %i is %i" %(op1, op2, op1+op2))
elif(op == '-'):
print("Substraction of %i and %i is %i" %(op1, op2, op1-op2))
elif(op == '/'):
print("Division of %i and %i is %i" %(op1, op2, op1/op2))
elif(op == '*'):
print("Product of %i and %i is %i" %(op1, op2, op1*op2))

Output:
sqrt 4
Square Root for the given number 4 is 2
sqr 4
Square for the given number 4 is 16
pow 2 2
2 power 2 is is 4
sci.py 4 + 3
Sum of 4 and 3 is 7
sci.py 4 - 3
Substraction of 4 and 3 is 1
sci.py 4 / 3
Division of 4 and 3 is 1
sci.py 4 "*" 3
Product of 4 and 3 is 12
CODE:

"Program to generate Report Card"


"Written by V.M.Pavithranathan"
rc={}
rc['rno']=int(input("Register Number: "))
rc['name']=input("Name: ")
rc['br']=input("Branch: ")
rc['sec']=input("Section: ")
rc['cat1']=int(input("Marks in CAT1: "))
rc['cat2']=int(input("Marks in CAT2: "))
rc['cat3']=int(input("Marks in CAT3: "))
rc['assn']=int(input("Marks in assignment: "))
rc['quiz']=int(input("Marks in quiz: "))

for (k, v) in rc.items():


print(k,": ", v)

OUTPUT:

Name: Pavithranathan
Branch: Civil
Section: A
Marks in CAT1: 37
Marks in CAT2: 5
Marks in CAT3: 38
Marks in assignment: 7
Marks in quiz: 7
cat2 : 5
cat1 : 37
br : Civil
rno : 181001036
sec : A
assn : 7
quiz : 7
cat3 : 38
name : Pavithranathan
CODE:

"Program to find the word frequency"


"Written by V.M.Pavithranathan"
s=input("Enter string: ")
d={}
p=s.split()
q=[]
for i in p:
if(i not in q):
q.append(i)
for x in q:
d[x]=p.count(x)
print(d)

OUTPUT:

Vijay
{'Vijay': 1}
CODE:
"Python program to find the occurence of word"
"Written by V.M.Pavithranathan(181001036)"
no_word=[]
temp=[]
d = {}
with open("chk.txt", "r") as fp:
no_line=0
l=0
for line in fp:
no_line =no_line + 1
words = line.split()
no_word.append(len(words))
temp.append(l)
temp.append(len(words))
d[l] = temp
temp=[]
l=l+1
fp.close()

no_words = sum(no_word)
print("--------Output----------")
print("No of lines are {0}".format(no_line))
print("No of words are {0}".format(no_words))
print(d)

OUTPUT:

--------Output----------
No of lines are 4
No of words are 20
{0: [0, 4], 1: [1, 4], 2: [2, 4], 3: [3, 8]}

S-ar putea să vă placă și