Aprial29 Py
Aprial29 Py
import random
import time
#generate a random number
#b = random.randint(1000,9999)
#print(b) #it returns a single object for every execution
#we want to generate 5 random numbers at a time
#We wanted to understand how much time the program is taking for excution
'''start = time.time() #standard time as epoch time from 1970 Jan 1st
#print(start)
for i in range(5):
#print(b)
print(random.randint(1000,9999))
time.sleep(2) #sleep() will give a halt duration for given number of seconds
end = time.time()
#print(end-start) #this will generate the time taken for script execution
'''
#here we are sending an automated email using Python -->Gmail
#First we need to create Gmail App password -->Two Step Verification
#Google Account -->Click on Security tab -->Switch on 2-Step Verfctn
#Once 2step verifctn is done ->Search for App passwords in top search bar
#then create your new app password
#we use smtplib(simple mail transfer protocol)
import smtplib
#first we will connect to Gmail Server
'''server = smtplib.SMTP('smtp.gmail.com',587)
#print(server)
#start the server
server.starttls()
#we will login to the gmail (username,app pwd)
server.login('[email protected]','hoam vmae oqwy cthy')
#you give away your msg
msg = "Hey guys this is my first mail using Python hurraayyyyy"
#send the mail
server.sendmail('[email protected]',
'[email protected]',msg)
print("Message sent")
#Now let us link OTP Generation and Email Automation together to send otp to
#mail
import random,smtplib,math
#using random and math module to generate random number
#digits variable with all possible number
digits = "0123456789"
#now we will create an output OTP variable
OTP = ""
#usng floor() and random() functions let us generate otp
for i in range(6):
#we need to update OTP variable
OTP += digits[math.floor((random.random()*10))]
#print(OTP)
msg = "Your OTP is \t" + OTP + "use it careful"
#print(msg)
#now link your mail code
server = smtplib.SMTP('smtp.gmail.com',587)
server.starttls()
server.login('[email protected]','hoam vmae oqwy cthy')
#give sender and receiver mail ids
sender = "[email protected]"
rece = input("Enter the mail to send otp")
server.sendmail(sender,rece,msg)
#print("OTP sent")
a = input("Enter the OTP received")
if a == OTP:
print("OTP is success")
else:
print("Fail sarigaa chuduu")
import datetime
#print(dir(datetime)) #returns all methods from module
#we want to get date object using datetime
from datetime import * #returns all functions from module internally
d = datetime.now() #returns datetime format
#print(d)
#print(type(d))
t = datetime.today()
#print(t)
#if we want only specific date
d = date(2024,6,27) #present,past,future any date
#print(d)
f = date.today()
#print(f)
#String Formatting -->converting datetime to string format
'''
%d -->day of the month,%b -->shortcut name for month,%B -->full name of mnth
%y -->two digit year,%Y -->four digit year,%a -->shortcut name for day of the
week %A -->full name for day of the week %j -->day number of the year
'''
d = f.strftime("The day is %A and we are in %B of %j day of year")
#print(d)
#Task-2 --> Take 3 inputs from user such as d,m,y -->convert to date format and
#give which month,what is the day of the week name,day number of the year and
#full 4 digit year