Page 104 - Digicode_AI_class_8
P. 104

Computational Thinking
                                                                                Information Literacy

              Write the output of the following programs:
              1.   def f(x):
                       y = x**x
                       return y
                   print ("testing...")
                   print ("passing the value 4")
                   z = f(2)
                   print ("the function returns", z)
              2.  def power(x, n):
                      result = 1
                      for i in range (n):
                            result *=x
                       return result
                   a = int (input ("Enter number"))
                   b = int (input ("Raise to power"))
                   pw = power (a, b)
                   print(a, "raise to power", b, "is", pw)





                                                                                   Experiential Learning
               Competency-based/Application-based questions                        Information Literacy

              Kazim wants to create a program in which he needs to multiply two numbers using functions. Which
              type of function will be suitable for Kazim?

              (i)  built-in function               (ii)  user-defined function





                                                                                   Experiential Learning
               code TASK                                                           Information Literacy


              Write a program using functions to:
              1.  check whether the input number is even or odd.

              2.  print a string 'orange' by calling a function.
















                102    DigiCode AI-VIII
   99   100   101   102   103   104   105   106   107   108   109