Ex-6 7

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

CSE304 – PYTHON PROGRAMMING WITH WEB FRAMEWORKS

EX NO. 6. Programs for exception handling


EX NO. 7. Programs to demonstrate recursive algorithms

1. Define a recursive function to find the sum of numbers between the two given
numbers x and y as input.

2. Write a recursive function to find out how many digits, a positive integer has.

3. The Hamming distance between two bit strings of length n is equal to the number
of bits in which the two strings differ. Compose a program that takes an integer k and
a bitstring s and writes all bitstrings that have Hamming distance at most k from s.

Eg., if k is 2 and s = 000, then the output should be


110 101 011

4. The program accepts a file containing a poem, as input. The poem should follow
the following rules:
a) All odd numbered lines should contain exactly 6 words and even-numbered lines
to contain exactly 5 words.
b) Odd numbered lines should contain a hyphen as the last character (this hyphen is
not counted in the 6 words count)
c) Even numbered lines should not start with uppercase letter

Non-compliance to the above rules are to be dealt with as follows:

a) Raise an exception named ‘WordCountException’ along with the actual count of


words present in the line
b) Raise an exception named ‘MissingHyphenException’ along with the line number
c) Raise an exception named ‘CaseMismatchException’ with a message ‘Line starts
with uppercase letter’

Write a python code to implement the above scenario. Also, print the count of each
type of exception raised, at the end of the execution.

You might also like