0% found this document useful (0 votes)
12 views3 pages

Python Library and String Methods Guide

The document contains two Python scripts. The first script defines a 'Library' function that calculates installment amounts for book rentals and checks book availability, while the second script defines a 'stringmethod' function that processes a string by removing special characters, reversing it, checking for the presence of certain strings, and counting word frequencies. Both scripts include error handling for various exceptions.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

Python Library and String Methods Guide

The document contains two Python scripts. The first script defines a 'Library' function that calculates installment amounts for book rentals and checks book availability, while the second script defines a 'stringmethod' function that processes a string by removing special characters, reversing it, checking for the presence of certain strings, and counting word frequencies. Both scripts include error handling for various exceptions.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#!

/bin/python3

import math
import os
import random
import re
import sys

#
# Complete the 'Library' function below.
#

def Library(memberfee,installment,book):
# Write your code here
b = ["Philosophers Stone","Order of Phoenix","Chamber of Secrets","Prisoner of
Azkaban","Goblet of Fire","Half Blood Prince","Deathly Hallows 1","Deathly Hallows
2"]
c = []
for i in b:
e = [Link]()
[Link](e)
book = [Link]()
if installment > 3:
raise ValueError("Maximum Permitted Number of Installments is 3")
elif installment == 0:
raise ZeroDivisionError("Number of Installments cannot be Zero.")
else:
print("Amount per Installment is {}".format(memberfee/installment))
if (not book in c):
raise NameError("No such book exists in this section")
else:
print("It is available in this section")

if __name__ == '__main__':

memberfee = int(input())
installment = int(input())
book = input()

try:
Library(memberfee,installment,book)

except ZeroDivisionError as e:
print(e)
except ValueError as e:
print(e)
except NameError as e:
print(e)

2. Python String Methods:

#!/bin/python3

import math
import os
import random
import re
import sys

#
# Complete the 'strmethod' function below.
#
# The function accepts following parameters:
# 1. STRING para
# 2. STRING spch1
# 3. STRING spch2
# 4. LIST li1
# 5. STRING strf
#

def stringmethod(para, special1, special2, list1, strfind):


# Write your code here
word1 = para
for char in special1:
word1 = [Link](char,"")
word2=word1[:70]
rword2 = word2[::-1]
print(rword2)
rword2 = [Link](" ","")
rword2 = [Link](rword2)
print(rword2)
for i in list1:
if [Link]( i, para):
presence = True
else:
presence = False
if presence:
print("Every string in "+ str(list1)+ " were present")
else:
print("Every string in "+ str(list1)+ " were not present")
splitword1 = [Link](" ")
print(splitword1[:20])
counts = dict()
words = [Link]()
for word in words:
if word in counts:
counts[word] += 1
else:
counts[word] = 1
d = dict((k,v) for k,v in [Link]() if v < 3)
lessfrequency = list(d)[::-1]
lessfrequency = lessfrequency[:20]
lessfrequency = lessfrequency[::-1]
print(lessfrequency)
lastidx = ''.join(word1).rindex(strfind)
print(str(lastidx))

if __name__ == '__main__':
para = input()
spch1 = input()

spch2 = input()

qw1_count = int(input().strip())

qw1 = []

for _ in range(qw1_count):
qw1_item = input()
[Link](qw1_item)

strf = input()

stringmethod(para, spch1, spch2, qw1, strf)

You might also like