aprial27.py
aprial27.py
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
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)
#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')