Documente Academic
Documente Profesional
Documente Cultură
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
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:
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:
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]}