Anjali Basera 12th
Anjali Basera 12th
Home work
ANJALI BASERA 12 TH
Sec “c” Roll no - 03
Submitted to-
Mr. Anshul Chand
1
Index
01. Write a program that takes a string with multiple words and then
capitalizes the first latter of each word and form a new string out 03
of it.
03. Program that receives two number in a function and return the
result of all arithmetic operations (+, -, *, /, %) on these numbers. 05
05. Write a program to get roll numbers, names and marks of the
students of a class and store these details in a file called 07
“Marks.txt”
06. Write a program to read a text file and display the count of
vowels and consonants in the file. 08
2
Qus1:
Write a program that takes a string with multiple words and then capitalizes
the first latter of each word and form a new string out of it.
Solution:
string = input("Enter a srting")
length = len(string)
a=0
end = length
string2 ='' #emptystring
while a < length:
if a == 0:
string2 += string[0].upper()
a += 1
elif (string[a] == '' and string[a+1] !=''):
string2 += string[a]
string2 += string [a+1].upper()
a += 2
else:
string2 += string[a]
a += 1
print("Original string :", string)
print("Captilized words string", string2)
3
Qus2:
Write a program that reads a string and checks whether it is palindrome
string or not.
Solution:
string = input("Enter a String - ")
if (string == string [::-1]):
print (string,"is a palindrome")
else:
print(string,"is not a palindrome")
4
Qus3:
Program that receives two number in a function and return the result of all
arithmetic operations (+, -, *, /, %) on these numbers.
Solution:
def arCalc(x,y):
return x+y,x-y, x*y, x/y, x%y
num1 = int(input("Enter number 1:"))
num2 = int (input ("Enter number 2:"))
add, sub, mult, div, mod = arCalc(num1, num2)
print ('Sum of given given numbers :', add)
print ('Subtract of given number :', sub)
print ('Product of given number :', mult)
print ("Division of given number :", div)
print ('Modulo of given number :', mod)
5
Qus4:
Write a program to display the size of a file in bytes.
Solution:
myfile = open('F:\Devesh.txt.txt')
str = myfile.read()
size = len(str)
print ('Size of the given file Devesh.txt is ')
print (size, 'bytes')
6
Qus5:
Write a program to get roll numbers, names and marks of the students of a class and
store these details in a file called “Marks.txt”
Solution:
count = int(input('How many studensts are there in the class?'))
fileout = open ("F:\Marks.txt", "w")
for i in range (count):
print ("Enter details for students", (i+1), "below")
rollno = int(input("Rollno:"))
name = input("Name :")
marks = float(input("Marks:"))
rec = str(rollno) + "," +name+","+str(marks)+'\n'
fileout.write(rec)
fileout.close()
7
Qus6:
Write a program to read a text file and display the count of vowels and consonants in
the file.
Solution:
myfile = open("F:\Answer.txt", "r")
ch = ""
vcount = 0
ccount = 0
while ch :
ch = myflie.read(1)
if chin ['a','A','e','E','i','I','o','O','u','U']:
vcount = vcount + 1
else:
ccount = ccount + 1
print ("Vowels in the file:", vcount)
print ("Consonants in the file:", ccount)
myfile.close()