Pixeltests 0 Comments

Python Made Easy for AI – Day 3


Functions

Excercise – 1:


Function Coinflip, On a coin toss if it’s Heads: India Bat’s, If it’s tails: Australia Bats:

def coinflip(Toss):
   if Toss == “Heads”:
       print (“India’s Batting”)
   else:
      print (“Australia’s Batting”)

coinflip(“Heads”)


Excercise – 2:


Function that returns square of any number

def square(n):      #This is Header
   squared = n ** 2          #This is body
   print (“Square of number is:”)
   print (squared)
   return squared #This is response

square(2) #This is a function call

Excercise – 3:

Few Inbuilt functions

maximum = max(8,92,34,119)
print maximum

minimum = min(8,92,34,119)
print minimum

length = len(“Type Your Name Here”)
print length

Leave a Comment