Determine whether the calling statement is valid where the f

Determine whether the calling statement is valid where the function definition has the header def bestFilm(year, film, star):. bestFilm(2012, \"Argo\", \"Ben Affleck\") bestFilm (2012, star = \"Ben Affleck\", film = \"Argo\") bestFilm (star= \"Ben Affleck\", film = \"Argo\", year = 2012) bestFilm (star =\"Ben Affleck\", 2012, film = \"Argo\") bestFilm () bestFilm(2012, director = \"Ben Affleck\", film = \"Argo\") In Exercises 43 through 46, determine whether the calling statement is valid where the function definition has the header def breakfast (toast, coffee, spam = 0, eggs = 0):. breakfast(2, spam = 1, eggs = 1, coffee = 1) breakfast (2, 1, 1, 1) breakfast(spam = 1, 1, eggs = 1, toast = 2) breakfast(2, 1, 1)

Solution

Given function definition:

   def bestFilm(year, film, star):
  

Function bestFilm accepts three parameters. None of the parameters have defined default values
  
(37) Given calling statement bestFilm(2012, \"Argo\", \"Ben Affleck\") is VALID.
  
   (a) Function call involves three values,
      
       (i) First value 2012 is assigned for variable year.
       (ii)   Second value \"Argo\" is assigned for variable film.
       (iii) Third value \"Ben Affleck\" is assigned for variable star.
      
   As number of arguments in both function definition and function call is satisfied, given calling statement is VALID.
  

(40) Given calling statement bestFilm(star=\"Ben Affleck\", 2012, film=\"Argo\") is INVALID.

   (a)   This function call involves Keyword arguments for two variables (film, star).
  
   (b) Python accepts arguments either if they are in correct order (or) they should use keyword arguments.
  
   (c) Variables star and film are specified as Key word arguments, they can be at any order.
  
   (d) But value 2012 is specified in wrong order and it is not a keyword argument.
  
   (e) This statement call raises a syntax error \"stating that positional argument follows keyword argument\" for 2012.
  
   Hence, given calling statement is INVALID.
________________________________________________________________________________________________________________

Given function definition:

   def breakfast(toast, coffee, spam=0, eggs=0):
  
Function breakfast accepts four parameters. Three of the parameters are specified with default values.

(43) Given calling statement breakfast(2, spam=1, eggs=1, coffee=1) is VALID.
  
   (a) Function call involves four values,
      
       (i)       First value 2 is assigned for variable toast.
       (ii)   Remaining three values are specified as Keyword arguments. So the value 1 is assigned to spam, value 1 is assigned to eggs and value 1 is assigned to coffee.
      
   As number of arguments in both function definition and function call are same and all values are correctly assigned, given calling statement is VALID.
  


(44) Given calling statement breakfast(2, 1, 1, 1) is VALID.
  
   (a) Function call involves four values,
      
       (i)       First value 2 is assigned for variable toast.
       (ii)   second value 1 is assigned for variable coffee.
       (ii)   Third value 1 is assigned for variable spam.
       (ii)   Fourth value 1 is assigned for variable eggs.
      
   As number of arguments in both function definition and function call are same and all values are correctly assigned, given calling statement is VALID.
  

 Determine whether the calling statement is valid where the function definition has the header def bestFilm(year, film, star):. bestFilm(2012, \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site