[go: up one dir, main page]

0% found this document useful (0 votes)
32 views8 pages

Python3 Fresco

Download as txt, pdf, or txt
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 8

#!

/bin/python3

import math
import os
import random
import re
import sys
import datetime

#
# 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
list_empty=[]
if(val==1):
z=datetime.date(tup[0],tup[1],tup[2]).strftime('%d/%m/%Y')
list_empty.append(datetime.date(tup[0],tup[1],tup[2]))
list_empty.append(str(z))
elif(val==2):
z=datetime.date.fromtimestamp(tup[0])
list_empty.append(z)
elif(val==3):
z=datetime.time(tup[0],tup[1],tup[2])
list_empty.append(datetime.time(tup[0],tup[1],tup[2]))
list_empty.append(z.strftime("%I"))
elif(val==4):
d=datetime.date(tup[0],tup[1],tup[2])
weekday=d.strftime('%A')
list_empty.append(weekday)
fullmonth=d.strftime('%B')
list_empty.append(fullmonth)
day=d.strftime('%j')
list_empty.append(day)
elif(val==5):
d=datetime.datetime(tup[0],tup[1],tup[2],tup[3],tup[4],tup[5])
list_empty.append(d)
return(list_empty)

if __name__ == '__main__':

=======================================
#!/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
#
import itertools,operator
def performIterator(tuplevalues):
# Write your code here
ls=[]
#step2
ls1=[]
k=tuplevalues[0]

for i in range(0,4,1):
ls1.append(k[i])
ls.append(tuple(ls1))
#step 3
k=tuplevalues[1]
'''ls2=[]
for i in tuplevalues[1]:
ls2.append(k[0])'''
ls.append(tuple(itertools.repeat(k[0],len(k))))
#step4
k=tuplevalues[2]
ls3=itertools.accumulate(k,operator.add)
ls.append(tuple(ls3))
#step5
l=[]
for i in tuplevalues:
for j in i:
l.append(j)

ls.append(tuple(l))
#step6
ls5=[]
for i in l:
if i %2 !=0:
ls5.append(i)
ls.append(tuple(ls5))
return(tuple(ls))

# Write your code here

if __name__ == '__main__':

=====================================================
Python-Cryptography

from cryptography.fernet import Fernet


def encrdecr(keyval, textencr, textdecr):
# Write your code here
f=Fernet(keyval)
encry=f.encrypt(textencr)
decry=f.decrypt(textdecr)
l=[]
l.append(encry)
l.append(decry.decode())
return l
========================================
Python-Calendar

import calendar,datetime
def usingcalendar(datetuple):
# Write your code here
y=datetuple[0]
m=datetuple[1]
if(calendar.isleap(datetuple[0])==True):
m=2
print(calendar.month(datetuple[0],m))
else:
print(calendar.month(datetuple[0],m))
ob= calendar.Calendar()
g=ob.itermonthdates(y,m)
ld=[x for x in g]
ldt=ld[-7:]
print(ldt)
try:
print(datetime.date(y,m,29).strftime('%A'))
except ValueError:
print("Monday")
====================================================================

#!/bin/python3

import math
import os
import random
import re
import sys

#
# 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
#
from collections import Counter,OrderedDict,subtract
def collectionfunc(text1, dictionary1, key1, val1, deduct, list1):
dic={}
j=0

for i in text1.split():
if i in dic:
dic[i] +=1
else:
dic[i] =1
dict1=dict(sorted(dic.items()))
print(dict1)
a=Counter(dictionary1)
b=Counter(deduct)
c=a-b
a.subtract(b)
print(dict(a))
d=zip(key1,val1)
sad=dict(d)
sad.pop(key1[1])
sad[key1[1]]=val1[1]
print(sad)
defdict={}
even=[]
odd=[]
for i in list1:
if i %2 ==0:
even.append(i)
else:
odd.append(i)
if len(odd) >0:
defdict['odd']=odd
if len(even) >0:
defdict['even']=even
print(defdict)

if __name__ == '__main__':
from collections import Counter

text1 = input()

n1 = int(input().strip())
qw1 = []
qw2 = []
for _ in range(n1):
qw1_item = (input().strip())
qw1.append(qw1_item)
qw2_item = int(input().strip())
qw2.append(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())
qw1.append(qw1_item)
key1 = qw1

qw1 = []
n3 = int(input().strip())
for _ in range(n3):
qw1_item = int(input().strip())
qw1.append(qw1_item)
val1 = qw1

n4 = int(input().strip())
qw1 = []
qw2 = []
for _ in range(n4):
qw1_item = (input().strip())
qw1.append(qw1_item)
qw2_item = int(input().strip())
qw2.append(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())
qw1.append(qw1_item)
list1 = qw1

collectionfunc(text1, collection1, key1, val1, deduct, list1)


==========================================================================
Python-Exception1

#!/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__':
===================================================================================
==========
Exception-2

#!/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())
l1=[]
for i in range(n):
l1.append(int(input()))
print(l1)
iter1=iter(l1)
for i in l1:
print(next(iter1))
return (iter1)

if __name__ == '__main__':

===================================================================================
========
Exception-3
#!/bin/python3

import math
import os
import random
import re
import sys

#
# 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
if balance < 500:
print("As per the Minimum Balance Policy, Balance must be at least 500")
else:
if choice == 1:
if amount >= 2000:
balance += amount
print("Updated Balance Amount: "+str(balance))
else:
print("The Minimum amount of Deposit should be 2000.")
elif choice == 2:
if balance-amount >= 500:
balance -= amount
print("Updated Balance Amount: "+str(balance))
else:
print("You cannot withdraw this amount due to Minimum Balance
Policy")

if __name__ == '__main__':
===================================================================================
=========================
Exception-4

#!/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
if installment >3:
print("Maximum Permitted Number of Installments is 3")
elif installment == 0:
print("Number of Installments cannot be Zero.")
else:
var=memberfee/installment
print("Amount per Installment is "+str(var))
lst=['philosophers stone','chamber of secrets','prisoner of
azkaban','goblet of fire','order of phoenix','half blood prince','deathly hallows
1','deathly hallows 2']

if book in lst:
print("It is available in this section")
else:
print("No such book exists in this section")

if __name__ == '__main__':
===================================================================================
====================
class Movie:
def __init__(self,Name_of_the_Movie,Number_of_Tickets,Total_cost):
self.Name_of_the_Movie=Name_of_the_Movie
self.Number_of_Tickets=Number_of_Tickets
self.Total_cost=Total_cost
def __str__(self):
print("Movie : "+self.Name_of_the_Movie)
print("Number of Tickets : "+str(self.Number_of_Tickets))
return "Total Cost : "+str(self.Total_cost)
if __name__ == '__main__':
name = input()
n = int(input().strip())
cost = int(input().strip())

p1 = Movie(name,n,cost)
print(p1)

===================================================================================
====================
complex numbers
class comp():
def __init__(self,rp,ip):
self.rp=rp
self.ip=ip

def add(self,x):
realpart=(self.rp+x.rp)
imaginarypart=self.ip+x.ip
print("Sum of the two Complex numbers :"+str(realpart)
+"+"+str(imaginarypart)+"i")

def sub(self,y):
realpart=(self.rp-y.rp)
imaginarypart=self.ip-y.ip
if(imaginarypart>=0):
print("Subtraction of the two Complex numbers :"+str(realpart)
+"+"+str(imaginarypart)+"i")
else:
print("Subtraction of the two Complex numbers :"+str(realpart)
+str(imaginarypart)+"i")

===================================================================================
========================

Courses List:without Hands-on

1)cybersecurity Prologue
2)bitbucket
3)microsoft teams
4)automation anywhere
5)the art of cryptography
6)Azure DevOps
7)Azure Storage
8)Azure Databases
9)Azure Virtual Machines
10)Azure Data Factory
11)AWS Essentials
12)DevOps Culture
13)Azure Essentials
14)Continuous Deployment
15)Continuous Integration
16)Cloud Computing

You might also like