Jalaj Pandey Bca 5 Assignment 5
Jalaj Pandey Bca 5 Assignment 5
BCA 5th
Assignment 5
Que 1 :-
def readFile():
file1 = input("Enter the path: ")
file = open(file1, 'r')
lines = file.read()
count = 0
vowel = ['a','e','i','o','u']
for i in lines:
if i in vowel:
count +=1
words = lines.split()
print(f'total words are {len(words)}')
print(f'total vowles are {count}')
readFile()
Que 2 :-
def dataStore():
dataList = ""
while True:
data = input()
dataList += data + '\n'
if data == "":
break
dataCap = ""
for i in dataList:
dataCap += i.capitalize()
with open('file.txt', 'w+') as file:
file.write(dataCap)
dataStore()
Que 3 :-
def read_content():
poem = input("enter the path: ")
file = open(poem, 'r')
lines = file.read()
countAlpha = 0
countSpace = 0
countLower = 0
countUpper = 0
countNwV = 0
countBeautiful = 0
vowels = ['A','E','I','O','U','a','e','i','o','u']
for i in lines:
if (ord(i)>=97 and ord(i)<=122) or (ord(i)>=65 and ord(i)<=90):
countAlpha += 1
if i == " ":
countSpace += 1
if (ord(i)>=97 and ord(i)<= 122):
countLower += 1
if (ord(i)>=65 and ord(i)<=90):
countUpper += 1
words = lines.split()
for i in words:
if i == 'beautiful':
countBeautiful += 1
if i[0] in vowels:
countNwV += 1
print(f'''Alphabets are {countAlpha},
Spaces are {countSpace},
Lowercase letters are {countLower},
Uppercase letters are {countUpper},
beautiful words are {countBeautiful},
word starts with Vowels are {countNwV}
''')
read_content()
Que 4 :-
Exception- Python has many built-in exceptions that are raised when your program encounters an
error (something in the program goes wrong).
When these exceptions occur, the Python interpreter stops the current process and passes it to the
calling process until it is handled. If not handled, the program will crash.
The critical operation which can raise an exception is placed inside the try clause. The code that
handles the exceptions is written in the except clause.
We can thus choose what operations to perform once we have caught the exception. Here is a
simple example.
Syntax-
try:
print(x)
except:
print("Something went wrong")
finally:
print("The 'try except' is finished")
Que 5 :-
def inverse1():
try:
num = input("Enter the number: ")
num = float(num)
inverse = 1.0 / num
except ValueError:
print("ValueError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
except:
print("Any other Error")
else:
print(inverse)
finally:
print("Function inverse Completed")
inverse1()