SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Y Daniel Lang
Chapter:
.functions
Exercise:
Check Point
Question:15 | ISBN:978013274719 | Edition: 6

Question

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)

 

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

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'.