0% found this document useful (0 votes)
71 views8 pages

Anjali Basera 12th

This document contains 6 programming questions and their solutions. It begins with an index listing the question number, title, and page number. Each question is numbered and presented with the required task. The solutions provide the code to complete the task in each question. The questions cover topics like capitalizing words in a string, checking for palindromes, arithmetic operations in a function, finding a file size, storing student data in a file, and counting vowels and consonants in a text file.

Uploaded by

pk pk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views8 pages

Anjali Basera 12th

This document contains 6 programming questions and their solutions. It begins with an index listing the question number, title, and page number. Each question is numbered and presented with the required task. The solutions provide the code to complete the task in each question. The questions cover topics like capitalizing words in a string, checking for palindromes, arithmetic operations in a function, finding a file size, storing student data in a file, and counting vowels and consonants in a text file.

Uploaded by

pk pk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Computer Science

Home work

ANJALI BASERA 12 TH
Sec “c” Roll no - 03

Submitted to-
Mr. Anshul Chand

1
Index

S.no. Title of the experiment Page no. Sign.


Teacher

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.

02. Write a program that reads a string and checks whether it is


palindrome string or not 04

03. Program that receives two number in a function and return the
result of all arithmetic operations (+, -, *, /, %) on these numbers. 05

04. Write a program to display the size of a file in bytes.


06

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()

You might also like