Python Oops
Python Oops
rword2 = word1[:70]
rword2 = rword2[::-1]
print(rword2)
flag = 0
for each in list1:
if each in para:
continue
else:
flag = 1
break
if flag:
print("Every string in {0} were not present".format(list1))
else:
print("Every string in {0} were present".format(list1))
splitted = word1.split()
print(splitted[:20])
ans = []
for each in splitted:
if splitted.count(each) < 3:
if each not in ans:
ans.append(each)
print(ans[-20:])
print(word1.rindex(strfind))
...................................................................................
...................................................................................
..
def generator_Magic(n1):
# Write your code here
lst = []
for i in range(3, n1+1):
M = i*(i*i + 1)/2
lst.append(M)
for i in range(len(lst)):
yield lst[i]
...................................................................................
...................................................................................
..
for i in range(len(lst)):
if (i % 2 == 0):
lst1.append(lst[i])
even += 2
else:
lst2.append(lst[i])
odd += 2
if (val):
for i in range(len(lst1)):
yield lst1[i]
else:
for i in range(len(lst2)):
yield lst2[i]
...................................................................................
...................................................................................
..
Task1
Task2
else:
print("Subtraction of the two Complex numbers :{}{}i".format(self.a -
other.a, self.b - other.b))
...................................................................................
...................................................................................
..
Task1
def display(self):
print("Share of Parents is {} Million.".format(round((self.t) / 2, 2)))
class son(parent):
def __init__(self, t, sp):
self.sp = sp
parent.__init__(self, t)
def son_display(self):
Percentage_for_son = (self.t * self.sp) / 100
print("Share of Son is {} Million.".format(round(Percentage_for_son, 2)))
print("Total Asset Worth is {} Million.".format(round(self.t, 2)))
class daughter(parent):
def __init__(self, t, dp):
self.dp = dp
parent.__init__(self, t)
def daughter_display(self):
Percentage_for_daughter = (self.t * self.dp) / 100
print("Share of Daughter is {}
Million.".format(round(Percentage_for_daughter, 2)))
print("Total Asset Worth is {} Million.".format(round(self.t, 2)))
Task2
def display(self):
print("This is a Rectangle")
class square:
def display(self):
print("This is a Square")
...................................................................................
...................................................................................
..
import datetime
def dateandtime(val, tup):
# Write your code here
l = []
if val == 1:
c1 = datetime.date(tup[0], tup[1], tup[2])
l.append(c1)
l.append(c1.strftime("%d") + "/" + c1.strftime("%m") + "/" +
c1.strftime("%Y"))
elif val == 2:
c1 = datetime.date.fromtimestamp(tup[0])
l.append(c1)
elif val == 3:
c1 = datetime.time(tup[0], tup[1], tup[2])
l.append(c1)
l.append(c1.strftime("%I"))
elif val == 4:
c1 = datetime.date(tup[0], tup[1], tup[2])
l.append(c1.strftime("%A"))
l.append(c1.strftime("%B"))
l.append(c1.strftime("%j"))
elif val == 5:
c1 = datetime.datetime(tup[0], tup[1], tup[2], tup[3], tup[4], tup[5])
l.append(c1)
return l
...................................................................................
...................................................................................
..
Python 3 - Functions and OOPs | 11 | Modules 2
import itertools
import operator
def performIterator(tuplevalues):
# Write your code here
l1 = []
ans = []
temp = itertools.cycle(tuplevalues[0])
count = 0
for i in temp:
l1.append(i)
count+=1
if count == 4:
break
ans.append(tuple(l1))
ans.append(tuple(list(itertools.repeat(tuplevalues[1]
[0],len(tuplevalues[1])))))
return tuple(ans)
...................................................................................
...................................................................................
..
return mainList
...................................................................................
...................................................................................
..
Python 3 - Functions and OOPs | 13 | Modules 4
import calendar
import datetime
def usingcalendar(datetuple):
year = datetuple[0]
leap = checkLeapYear(year)
if leap == 1:
month = 2
else:
month = datetuple[1]
print(calendar.month(year, month))
m = calendar.monthcalendar(year, month)
mondays = [week[0] for week in m if week[0] > 0]
day = mondays[-1]
lst = []
MONTH = month
YEAR = year
for i in range(7):
d = datetime.date(year, month, day)
lst.append(d)
else:
if ((month == 1) or (month == 3) or (month == 5) or (month == 7) or
(month == 8) or (month == 10) or (
month == 12)) and (day == 31):
day = 0
if (month == 12):
month = 1
year = year + 1
else:
month = month + 1
day = day + 1
print(lst)
print(days[pos])
...................................................................................
...................................................................................
..
import collections
def collectionfunc(text1, dictionary1, key1, val1, deduct, list1):
# Write your code here
d = {}
for each in text1.split():
if each in d:
d[each] += 1
else:
d[each] = 1
sort_d = dict(sorted(d.items(), key=lambda kv: kv[0]))
print(sort_d)
cou = collections.Counter(dictionary1)
for each in deduct:
cou[each] -= deduct[each]
print(dict(cou))
orde = collections.OrderedDict()
for i in range(len(key1)):
orde[key1[i]] = val1[i]
del orde[key1[1]]
orde[key1[1]] = val1[1]
print(dict(orde))
...................................................................................
...................................................................................
..
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")
...................................................................................
...................................................................................
..
def FORLoop():
# Write your code here
n = int(input())
l1 = []
for i in range(n):
l1.append(int(input()))
print(l1)
iter1 = iter(l1)
for i in range(len(l1)):
print(next(iter1))
return iter1
...................................................................................
...................................................................................
..
def Bank_ATM(balance,choice,amount):
# Write your code here
flag = 0
if balance < 500:
print("As per the Minimum Balance Policy, Balance must be at least 500")
else:
if (choice == 1):
if amount < 2000:
print("The Minimum amount of Deposit should be 2000.")
else:
flag = 1
balance += amount
if(choice == 2):
if(balance - amount)<500:
print("You cannot withdraw this amount due to Minimum Balance
Policy")
else:
flag = 1
balance -= amount
if(flag):
print("Updated Balance Amount: ", format(balance))
...................................................................................
...................................................................................
..
def Library(memberfee,installment,book):
# Write your code here
if(installment > 3):
print("Maximum Permitted Number of Installments is 3")
else:
if (installment == 0):
print("Number of Installments cannot be Zero.")
else:
print("Amount per Installment is {}".format(memberfee/installment))
ListOfBooks = ["philosophers stone", "chamber of secrets", "prisoner of
azkaban", "goblet of fire", "order of phoenix", "half blood price", "deathly
hallows 1", "deathly hallows 2"]
book = book.lower()
if book in ListOfBooks:
print("It is available in this section")
else:
print("No such book exists in this section")