###String-1
#!/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)
##magic
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'Magic_const' function below.
#
#
#
# The function accepts INTEGER n1 as parameter.
#
def generator_Magic(n1):
# Write your code here
n=3
while n<=n1:
yield (n*((n*n)+1))/2
n=n+1
if __name__ == '__main__':
n = int(input().strip())
for i in generator_Magic(n):
print(int(i))
gen1 = generator_Magic(n)
print(type(gen1))
#!/bin/python3
import math
import os
import random
import re
import sys
# Write your code here
class Movie:
def __init__(self,n,no,p):
self.n=n
[Link]=no
self.p=p
def __str__(self):
return f"Movie : {self.n}\nNumber of Tickets : {[Link]} \nTotal Cost :
{self.p}"
if __name__ == '__main__':
name = input()
n = int(input().strip())
cost = int(input().strip())
p1 = Movie(name,n,cost)
print(p1)
#!/bin/python3
import math
import os
import random
import re
import sys
#
#Write your code here
class comp:
def __init__(self,a,b=0.0):
self.a=a
self.b=b
def add(self,o):
aa=(self.a + o.a)
a1=(self.b + o.b)
if a1<0:
print(f"Sum of the two Complex numbers :{aa}{a1}i")
else:
print(f"Sum of the two Complex numbers :{aa}+{a1}i")
def sub(self,o):
aa=(self.a - o.a)
a1=(self.b - o.b)
if a1<0:
print(f"Subtraction of the two Complex numbers :{aa}{a1}i")
else:
print(f"Subtraction of the two Complex numbers :{aa}+{a1}i")
if __name__ == '__main__':
real1 = int(input().strip())
img1 = int(input().strip())
real2 = int(input().strip())
img2 = int(input().strip())
p1 = comp(real1,img1)
p2 = comp(real2,img2)
[Link](p2)
[Link](p2)
#!/bin/python3
import math
import os
import random
import re
import sys
class parent:
def __init__(self,total_asset):
self.total_asset = total_asset
def display(self):
print("Total Asset Worth is "+str(self.total_asset)+" Million.")
print("Share of Parents is "+str(round(self.total_asset/2,2))+" Million.")
# It is expected to create two child classes 'son' & 'daughter' for the above class
'parent'
#
#Write your code here
class son(parent):
def __init__(self,t,sp):
[Link]=sp
parent.__init__(self,t)
def son_display(self):
print("Share of Son is",round(t*(sp/100),2),"Million.")
class daughter(parent):
def __init__(self,t,dp):
[Link]=sp
parent.__init__(self,t)
def daughter_display(self):
print("Share of Daughter is",round(t*(dp/100),2),"Million.")
if __name__ == '__main__':
t = int(input())
sp = int(input())
dp = int(input())
obj1 = parent(t)
obj2 = son(t,sp)
obj2.son_display()
[Link]()
obj3 = daughter(t,dp)
obj3.daughter_display()
[Link]()
print(isinstance(obj2,parent))
print(isinstance(obj3,parent))
print(isinstance(obj3,son))
print(isinstance(obj2,daughter))
#!/bin/python3
import math
import os
import random
import re
import sys
# Write your code here
class rectangle:
def display(self):
print('This is a Rectangle')
def area(self,a,b):
self.a=a
self.b=b
print('Area of Rectangle is ',(self.a*self.b))
class square:
def display(self):
print('This is a Square')
def area(self,s):
self.s=s
print('Area of square is ',(self.s)**2)
if __name__ == '__main__':
l = int(input())
b = int(input())
s = int(input())
obj1 = rectangle()
[Link]()
[Link](l,b)
obj2 = square()
[Link]()
[Link](s)
#!/bin/python3
import math
import os
import random
import re
import sys
from datetime import datetime
from datetime import time
#
# Complete the 'dateandtime' function below.
#
# The function accepts INTEGER val as parameter.
# The return type must be LIST.
#
def dateandtime(val,tup):
# Write your code here
if val ==1:
a=[datetime(*tup).date(),datetime(*tup).date().strftime("%d/%m/%Y")]
elif val ==2:
a=[[Link](*tup).date()]
elif val ==3:
a=[time(*tup),time(*tup).strftime("%I")]
elif val ==4:
a=[datetime(*tup).strftime("%A"),datetime(*tup).strftime("%B"),datetime(*tup).strft
ime("%j")]
elif val ==5:
a=[datetime(*tup)]
return a
if __name__ == '__main__':
val = int(input().strip())
if val ==1 or val==4 or val ==3:
qw1_count=3
if val==2:
qw1_count=1
if val ==5:
qw1_count=6
qw1 = []
for _ in range(qw1_count):
qw1_item = int(input().strip())
[Link](qw1_item)
tup=tuple(qw1)
ans = dateandtime(val,tup)
print(ans)
#!/bin/python3
import math
import os
import random
import re
import sys
import itertools
#
# Complete the 'usingiter' function below.
#
# The function is expected to return a TUPLE.
# The function accepts following parameters:
# 1. TUPLE tupb
#
def performIterator(tuplevalues):
# Write your code here
l1=[]
l2=[]
l3=[]
l4=[]
y=[Link](tuplevalues[0])
for i in range (4):
[Link](next(y))
x=tuple(l2)
[Link](x)
rp=[Link](tuplevalues[1][0])
for i in range(len(tuplevalues[1])):
[Link](next(rp))
m=tuple(l3)
[Link](m)
acc=[Link](tuplevalues[2])
for i in range(len(tuplevalues[2])):
[Link](next(acc))
n=tuple(l4)
[Link](n)
l5=[]
ch=[Link](tuplevalues[0],tuplevalues[1],tuplevalues[2],tuplevalues[3])
for i in ch:
[Link](i)
n=tuple(l5)
[Link](n)
l6=[]
chm=[Link](lambda x: x%2==0, n)
for i in chm:
[Link](i)
o=tuple(l6)
[Link](o)
final=tuple(l1)
return final
if __name__ == '__main__':
length = int(input().strip())
qw1 = []
for i in range(4):
qw2 = []
for _ in range(length):
qw2_item = int(input().strip())
[Link](qw2_item)
[Link](tuple(qw2))
tupb = tuple(qw1)
q = performIterator(tupb)
print(q)
#!/bin/python3
import math
import os
import random
import re
import sys
from [Link] import Fernet
#
# Complete the 'encrdecr' function below.
#
# The function is expected to return a LIST.
# The function accepts following parameters:
# 1. STRING keyval
# 2. STRING textencr
# 3. Byte-code textdecr
#
def encrdecr(keyval, textencr, textdecr):
# Write your code here
l = list()
f = Fernet(keyval)
textencr = [Link](textencr)
[Link](textencr)
textdecr = [Link](textdecr)
o = [Link]('utf-8')
fi = format(o)
[Link](fi)
return l
if __name__ == '__main__':
fptr = open([Link]['OUTPUT_PATH'], 'w')
file = open('[Link]', 'rb')
key = [Link]() # The key will be type bytes
[Link]()
keyval = key
textencr = str(input()).encode()
textdecr = str(input()).encode()
result = encrdecr(keyval, textencr, textdecr)
bk=[]
f = Fernet(key)
val = [Link](result[0])
[Link]([Link]())
[Link](result[1])
[Link](str(bk) + '\n')
[Link]()
#!/bin/python3
import math
import os
import random
import re
import sys
import calendar
import datetime
#
# Complete the 'calen' function below.
#
# The function accepts TUPLE datetuple as parameter.
#
def usingcalendar(datetuple):
# Write your code here
cal=[Link]()
if [Link](datetuple[0]):
month =2
[Link](datetuple[0],month)
print()
else:
month=datetuple[1]
[Link](datetuple[0],month)
print()
w=[Link](datetuple[0],month)
last7=[]
for i in w:
[Link](i)
print(last7[(len(last7)-7):len(last7)])
freq=[Link](datetuple[0],month)
print(calendar.day_name[freq[0]])
if __name__ == '__main__':
qw1 = []
for _ in range(3):
qw1_item = int(input().strip())
[Link](qw1_item)
tup=tuple(qw1)
usingcalendar(tup)
#!/bin/python3
import math
import os
import random
import re
import sys
import collections
from collections import Counter
from collections import OrderedDict
from collections import defaultdict
#
# Complete the 'collectionfunc' function below.
#
# The function accepts following parameters:
# 1. STRING text1
# 2. DICTIONARY dictionary1
# 3. LIST key1
# 4. LIST val1
# 5. DICTIONARY deduct
# 6. LIST list1
#
def collectionfunc(text1, dictionary1, key1, val1, deduct, list1):
# Write your code here
wc={}
l=[Link]()
[Link]()
a=dict(Counter(l))
print(a)
c1=Counter(dictionary1)
c2=Counter(deduct)
[Link](c2)
b=dict(c1)
print(b)
c=OrderedDict()
for i in range(0,len(key1)):
c[key1[i]]=val1[i]
[Link](key1[1])
c[key1[1]]=val1[1]
d=dict(c)
print(d)
even=[]
odd=[]
e=defaultdict(list)
extr=[]
for x in list1:
if type(x)==int:
[Link](x)
for num in extr:
if num%2==0:
e['even'].append(num)
else:
e['odd'].append(num)
f=dict(e)
print(f)
if __name__ == '__main__':
from collections import Counter
text1 = input()
n1 = int(input().strip())
qw1 = []
qw2 = []
for _ in range(n1):
qw1_item = (input().strip())
[Link](qw1_item)
qw2_item = int(input().strip())
[Link](qw2_item)
testdict={}
for i in range(n1):
testdict[qw1[i]]=qw2[i]
collection1 = (testdict)
qw1 = []
n2 = int(input().strip())
for _ in range(n2):
qw1_item = (input().strip())
[Link](qw1_item)
key1 = qw1
qw1 = []
n3 = int(input().strip())
for _ in range(n3):
qw1_item = int(input().strip())
[Link](qw1_item)
val1 = qw1
n4 = int(input().strip())
qw1 = []
qw2 = []
for _ in range(n4):
qw1_item = (input().strip())
[Link](qw1_item)
qw2_item = int(input().strip())
[Link](qw2_item)
testdict={}
for i in range(n4):
testdict[qw1[i]]=qw2[i]
deduct = testdict
qw1 = []
n5 = int(input().strip())
for _ in range(n5):
qw1_item = int(input().strip())
[Link](qw1_item)
list1 = qw1
collectionfunc(text1, collection1, key1, val1, deduct, list1)
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'Handle_Exc1' function below.
#
#
def Handle_Exc1():
# Write your code here
a=int(input())
b=int(input())
if(a>150 or b<100):
print("Input integers value out of range.")
elif(a+b>400):
print("Their sum is out of range")
else:
print("All in range")
if __name__ == '__main__':
try:
Handle_Exc1()
except ValueError as exp:
print(exp)
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'FORLoop' function below.
#
def FORLoop():
# Write your code here
n=int(input())
l=[]
for i in range(0,n):
item=int(input())
[Link](item)
print(l)
iter1=iter(l)
for j in iter1:
print(j)
return iter1
if __name__ == '__main__':
try:
d = FORLoop()
print(type(d))
print(next(d))
except StopIteration:
print('Stop Iteration : No Next Element to fetch')
#!/bin/python3
import math
import os
import random
import re
import sys
class MinimumBalanceError(Exception):
pass
class MinimumDepositError(Exception):
pass
#
# Complete the 'Bank_ATM' function below.
#
# Define the Class for user-defined exceptions "MinimumDepositError" and
"MinimumBalanceError" here
def Bank_ATM(balance,choice,amount):
# Write your code here
b=(balance-amount)
if(balance<500):
raise ValueError("As per the Minimum Balance Policy, Balance must be at
least 500")
elif(balance<500 and choice==1):
raise MinimumDepositError("As per the Minimum Balance Policy, Balance must
be at least 500")
elif(((b<500)or (amount>balance<500)) and choice==2):
raise MinimumBalanceError("You cannot withdraw this amount due to Minimum
Balance Policy")
elif(choice==1 and amount<2000):
raise MinimumDepositError("The Minimum amount of Deposit should be 2000.")
elif(choice==1 and amount>2000):
balance=balance+amount
print("Updated Balance Amount: ",balance)
else:
balance=balance-amount
print("Updated Balance Amount: ",balance)
if __name__ == '__main__':
bal = int(input())
ch = int(input())
amt = int(input())
try:
Bank_ATM(bal,ch,amt)
except ValueError as e:
print(e)
except MinimumDepositError as e:
print(e)
except MinimumBalanceError as e:
print(e)
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'Library' function below.
#
def Library(memberfee,installment,book):
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.")
elif installment<=3:
a=memberfee / installment
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)