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()

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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()

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY