Show the result of the following programs: (a) def main():max = 0getMax(1, 2, max)print(max)def getMax(value1, value2, max):if value1 > value2:max = value1else:max = value2main() (b) def main():i = 1while i <= 6:print(function1(i, 2))i += 1def function1(i, num):line = ""for j in range(1, i):line += str(num) + " "num *= 2return linemain() (c)def main():# Initialize timestimes = 3print("Before the call, variable","times is", times)# Invoke nPrintln and display timesnPrint("Welcome to CS!", times)print("After the call, variable","times is", times)# Print the message n timesdef nPrint(message, n):while n > 0:print("n = ", n)print(message)n -= 1main() (d)def main():i = 0while i <= 4:function1(i)i += 1print("i is", i)def function1(i):line = " "while i >= 1:if i % 3 != 0:line += str(i) + " "i -= 1print(line)main()
Show the result of the following programs:
(a) def main():
max = 0
getMax(1, 2, max)
print(max)
def getMax(value1, value2, max):
if value1 > value2:
max = value1
else:
max = value2
main()
(b) 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()
(c)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()
(d)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()
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 3 images