Show the result of the following programs:
def main():
max = 0
getMax(1, 2, max)
print(max)
def getMax(value1, value2, max):
if value1 > value2:
max = value1
else:
max = value2
main()
(a)
def main():
i = 1
while i <= 6:
print(function1(i, 2))
i += 1
def function1(i, num):
line = ""
for j in range(1, i):
line += str(num) + " "
num *= 2
return line
main()
(b)
def main():
# Initialize times
times = 3
print("Before the call, variable", "times is", times)
# Invoke nPrintln and display times
nPrint("Welcome to CS!", times)
print("After the call, variable", "times is", times)
# Print the message n times
def nPrint(message, n):
while n > 0:
print("n = ", n)
print(message)
n -= 1
main()
(c)
def main():
i = 0
while i <= 4:
function1(i)
i += 1
print("i is", i)
def function1(i):
line = " "
while i >= 1:
if i % 3 != 0:
line += str(i) + " "
i -= 1
print(line)
main()
(d)
Sorry the answer is not available at the moment…
If you are able to find the answer, please make sure to post it here. So that your Juniors have smile on their lips and feel happy.
Spread the 'tradition of sharing'.