Phone

+919997782184

Email

support@roboticswithpython.com

Geeks of Coding

Join us on Telegram

Home Forums Assignment courserra Python for Everybody – Specialization Programming for Everybody (Getting started with Python) Week 6 Chapter 4, Programming for Everybody (Getting started with Python)

Viewing 0 reply threads
  • Author
    Posts
    • #861
      Abhishek TyagiAbhishek Tyagi
      Keymaster

      1. Which Python keyword indicates the start of a function definition?

        Answer-

      def

      2. In Python, how do you indicate the end of the block of code that makes up the function?

        Answer-

      You de-indent a line of code to the same indent level as the def keyword

      3. In Python what is the input() feature best described as?

        Answer-

      A built-in function

      4. What does the following code print out?

      	def thing():
          	print('Hello')
      
      	print('There')
        Answer-

      There

      5. In the following Python code, which of the following is an “argument” to a function?

      x = 'banana'
      y = max(x)
      print(y)
        Answer-

      x

      6. What will the following Python code print out?

      def func(x) :
          print(x)
      
      func(10)
      func(20)
        Answer-
      10
      20

      7.Which line of the following Python program will never execute?

      def stuff():
          print('Hello')
          return
          print('World')
      
      stuff()
        Answer-

      print ('World')

      8. What will the following Python program print out?

      def greet(lang):
          if lang == 'es':
              return 'Hola'
          elif lang == 'fr':
              return 'Bonjour'
          else:
              return 'Hello'
      
      print(greet('fr'),'Michael')
        Answer-

      Bonjour Michael

      9. What does the following Python code print out? (Note that this is a bit of a trick question and the code has what many would consider being a flaw/bug – so read carefully).

      def addtwo(a, b):
          added = a + b
          return a
      
      x = addtwo(2, 7)
      print(x)
        Answer-

      2

      10. What is the most important benefit of writing your own functions?

        Answer-

      Avoiding writing the same non-trivial code more than once in your program

Viewing 0 reply threads
  • You must be logged in to reply to this topic.