0% found this document useful (0 votes)
7 views

aprial27.py

Uploaded by

beherasuprabath
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)
7 views

aprial27.py

Uploaded by

beherasuprabath
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
You are on page 1/ 3

'''

let us understand in detail about functions,some interesting modules


playing a game,getting public data from Instagram,Email Automation

def fname(*args,**kwargs):
"""Doc String (descprtin)"""
statement(s)...
return value(s)....
fname(*a,**b)
'''
#Let us take a simple function to start
'''def add(a,b):
"""Simple Function to take two arguments"""
c = a+b
return c
print(add(5,2.3))
print(add('code','gnan'))
print(add([1,5,6],[7,5,9]))
#print(add(58,2,6,9)) #TypeError as Positional Arguments are failed
#number of arguments in function definition should match with the function
#call

#Variable length arguments -->The number of arguments are not fixed we can
#define any number of arguments by using * notation data is stored in tuple

def new(*a):
"""To understand *args usage"""
print(a)
print(type(a))
new()
new(5,8,9,6)
new('codegnan',5.3,56,2+3j)
'''
#To create a function which can accept any number of arguments and return
#the sum of values
'''
def check(*a):
"""Function to return sum of values"""
print(a)
d = 0 #output variable to return the sum
for i in a:
#print(i)
if type(i) == int or type(i)== float: #we are considering only int and
float
d=d+i #d+=i
return d
#print(check(5,3,-2,6))
print(check(15,2.3,'abhi',12,2+3j,-6))

#Keyword arguments -->We can define any name for the arguments and
#use it specifically otherwise it returns TypeError
def details(name,age,place,college='NRI'):
"""Keyword arguments usage"""
print(f'{name} is in {place} and of {age} old,college is {college}')
#details('Codegnan',5,'Vjwda')
#details(15,'NRI','Vjwda') #to avoid such we use keywords
details(age=15,name="NRI",place="Vjwda")
details("Saketh",29,"Vjwda",college="KLU")
details("Saketh",29,"Vjwda",college="KLU",grade='A') #as keyword
#grade is not defined

#Keyword variable length arguments -->we can define any number of


#arguments by using ** notation data is stored dict...

def final(**a):
"""Usage of **kwargs"""
print(a)
print(type(a))
final()
final(item = "bread",price = 30)
'''
#Using both *args and **kwargs together
'''def both(*a,**b):
"""Usage of both *args and **kwargs"""
print(a)
print(b)
both(1,5,8,2,'poll',age = 29,name="Saketh",place="Codegnan")
#both(12,-5,age=5,1.3,26,place='NRI') #Syntax Error -->Positional Argument
#follows Keyword arguments
'''
#Task-1 : Create a BMI calculator function similar to last class task but
#use ** as arguments (name,weight,height,place)

#Datatypes -->Operators -->Control Statements -->Functions


#Modules -->Data from Instagram,Number Game (random module),Story
#Generator,Email Automation using Python

#We need to use 'import' keyword

#Download data from Instagram -->pypi (Python Package Index)


#instaloader --> pip install instaloader
#Python >3.8 i recommend 3.10.7

#https://instaloader.github.io/
'''
import instaloader
#first we need to get the Instaloader class
mod = instaloader.Instaloader()
#print(mod)
#now you can give the Public Instagram profile name
#mod.login(user,passwd) #first you need to login if you want to try
profile_name = input("Enter the IG profile name") #check with private profile
mod.download_profile(profile_name)
'''
#Playing a Number game,story generation,Rock Paper Scissors,OTP Generation...
#random module
#Number Guessing Game
import random
#first accept machine input
'''machine = random.randint(1,10)
#accept input from user
guess = int(input("Enter the number in 1-10")) #take a simple range
#we will use loops
while machine!=guess:
if guess < machine:
print("OOPS lower number enter again")
guess = int(input("Enter the number in 1-10"))
elif guess > machine:
print("Ohhoo higher number try again")
guess = int(input("Enter the number in 1-10"))
else:
break
print(f"Hurraayyy we got the number it is {machine}")
'''
#Generate some random text --> random has choice() function

names = ['Saketh','Codegnan','Abhi','Akash','Naveen']
b = random.choice(names)
print(f'{b} is in NRI College and today is Saturday')

#Task-2 --> Create a Story of 3-4 lines using random module


#hint : create where,when,what,who,how.... lists and generate possible
#combinations of text

#Rock Paper Scissors game


user = input("Enter Rock,paper,Scissors").lower()
print(user)
machine = random.choice(['Rock','Paper','Scissor']).lower()
print(machine)
if user == 'rock' and machine == "paper":
print("Machine won")
#..... finish the game
#....

#Task-3 : Create a Function and give option to user whether to play


#number game or Rock Paper Scissors with good looking output...

#Submit 5 tasks on [email protected] with


#subject as Name,Rollno,branch

#IT,AIML CRs -->8106429771


#drive link

#In next class we will work on Email Automation,OTP Expiration and


#Working on Images -->AI (Computer Vision)

#Google -->Codegnan Academy -->Python (Free)

You might also like