HNM [12] 1. Consider the function which, defined below. def which (x, y): if x >
ID: 3906610 • Letter: H
Question
HNM [12] 1. Consider the function which, defined below. def which (x, y): if x > 3 and y y or x > 7: print ('B') else: print('C') What is printed by each of these function calls? a. which (1, 9) b. which (4, 2) c. which (8, 9) d. which(1, 0) [15] 2. What is printed by the Python code? (Note: The code prints each time through the loop body!) x = 22 y = 2 while x > 5: if x > 10: x = x - y y = 2*y #6 else: x = x - 2 print (x, end='') #8 OWNA [13]3. What is printed by the Python code? Remember 'e' is not equal to 'E'. for word in ['And', 'THE', 'is', 'OH', 'a']: #1 if word. upper() == word: print (word.lower()) : 3Explanation / Answer
Please find the answe below:
which(1,9) here x is less than 7 so will print B
which(4,2) here x is greater than 3 and y less than 8 so will print A
which(8,9) here both if and elif condition not satisfied so will print C
which(1,0) => which(1,9) here x is less than 7 so will print B
which(1,9) => B
which(4,2) => A
which(8,9) => C
which(1,0) => B
-----------------------------------------------------------------------------------
x = 22
y =2
while x > 5 :
if x>10 :
x = x-y;
y = 2*y
else:
x = x-2
print(x,end=' ')
First x is 22 so will go inside if so
x = x -y = 22 -2 = 20
y = 2 *y =4
20 will print
next:
again x is greater than 10 so if will execute
x = 20-4=16
y = 4*2=8
16 will print
again x is greater than 10 so if will execute
x = 16-8=8
y = 8*2=16
8 will print
now x is less than 10 so else will execute
x = 8 -2 = 6
6 will print
now x is less than 10 so else will execute
x = 6 -2 = 4
4 will print
now x is less than 5 so loop will terminate
so result is : 20 16 8 6 4
-----------------------------------------------------------------------------------
for word in ['And','THE','is','OH','a'] :
if word.upper() == word:
print(word.lower());
for word will loop from all string word.
Now if word.upper() == word it will filter only those string that is completely upppercase so only THE and OH will pass
now print will print in lower case so the oh will print
result is
the
oh
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.