Question

5. What is the output of the below program? (14 marks) def Fungsi (xx): print (x is , xx) values=[8 ,2 , 6 , 6 ,2 ,6) c=0 f

0 0
Add a comment Improve this question Transcribed image text
Answer #1

OUTPUT :-

('x is ', 2)
('Return ', 2)
('The A is ', 2)
('x is ', 6)
('Return ', 3)
('x is ', 7)
('Return ', 100)
('The B is ', 103)

--------------------------------------XXXXXXXXXXXXXXXXXXXXXX-----------------------------------------------

program with explanation :-

"""

    In this python function Fungsi(xx) function defines

    which takes int value and returns int value

    Fungsi() function count the appearence of parameter int no in the values array

    and send back the count of this int no to the calling function

    if the values array does not contain this parameter value the by default it sends 100.

    output :-

        Fungsi() function first prints parameter value then its returning value

        and then calling function prints returing value.

"""

# Defines Fungsi() function

def Fungsi(xx):

    # print parameter value on the console

    print("x is ",xx)

    #declaration of values array and count variable c

    values = [8, 2, 6, 6, 2, 6]

    c = 0

    # Iterates over values array. len() function returns length of array

    for i in range(len(values)):

        # increment c if parameter value present in array value

        if (values[i] == xx):

            c = c+1

    # It retruns value of c if c is greater than 0

    if (c > 0):

        print("Return ",c)

        return c

    # It retruns value of 100 if c is less than 0

    else:

        c = 100

        print("Return ",c)

        return c

# calls Fungsi() function with value 2 and store return value in A

A = Fungsi(2)

# print this value

print("The A is ",A)

# # calls Fungsi() function with values 6 and 7 and add those return values then store  it in B

B = Fungsi(6) + Fungsi(7)

# print this value

print("The B is ",B)

Add a comment
Know the answer?
Add Answer to:
5. What is the output of the below program? (14 marks) def Fungsi (xx): print ("x...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT