ues Part 1: Consider the following Python script that contains a function called
ID: 3604934 • Letter: U
Question
ues Part 1: Consider the following Python script that contains a function called 'even_odd" which take the x (an integer) as the parameter and retum "even" if x is an even number and "odd" otherwise Answer the following questions Line 01: #This function returns Even or odd according to the integer x Line 02: def even_odd (x): Line 03: if x%2 =-0: Line 04: Line 05: else: Line 06: Line 07: Line 08: akes an integer from user and calls the function Line 09: a input ("Enter an integer:") Line 10: print a, is an", even odd (a), "number" return even" return "odd" a. At which line the computer starts execution of this script? Points 2 Line o3 Find one example for each of the following terms from the above Python script Keyword Built-in function Function name Function call Parameter Argument Local variable b. c. What will be the output of this script for the following user input? Output of the script even 3 d. Which of the followings are valid function call(s) to the function even_odd? (Note: There may be more than one answer.) i. even odd(s) ii. even _odd (len("Hello World") ) even odd (-5) v. even odd (2,3) v. even_odd (2+3) Part 2: Suppose the two return statements in even odd fu above(Note: Your answer may contains any number of lines) nction are changed to two print mas. Then, how would you change Line 10 to get the same output asExplanation / Answer
a)
The computer starts execution of this script and Line 09.
as even_odd is a method, It is executed only when called.
excluding comments the program start by getting input from user.
b)
build-in function : input
function name : even_odd
function call : even_odd(a)
parameter : x (parameter defined in function even_odd)
argument : a (value passed to function even_odd)
local variable : x (x is local to the function even_odd)
c)
2 :: even
3 :: odd
d)
i. even_odd(5)
ii. even_odd(len("Hello World")) # this is valid as len returns a number
iii. even_odd(-5) # it is a number so valid
v. even_odd(2+3) # 2+3 is 5, so it is valid
iv. even_odd(2,3) is invalid becuase even_odd takes only 1 parameter.
Part2)
def even_odd(n):
if(n%2==0):
print "even",
else:
print "odd",
return ''
a = input("Enter an integer:")
print a,"is an",even_odd(a),"number"
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.