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)
5. What is the output of the below program? (14 marks) def Fungsi (xx): print ("x...
12. What is the output of this program? Your answer: 1 def main(): 2 print('The numbers are:') 3 for i in range (2,25): 4 isone (i) 5 def isone (number): isOne = True i = 2 while i < number and is one: if number % i == 0: 10 isOne = False 11 i += 1 Lou if isOne == True: 13 print("\t', i) 14 main() 12 13. What is the output of this program? Your answer: for i...
Consider the following small program. What will the output be? def foo(x): print(x) def bar(): return 3 def baz(y, z): return y * z a = bar() + 2 b = baz(a, 2) foo(a + b) 10 3 2 25 none of these 15
Consider the following small program. What will the output be? def foo(x): return x + 2 x = 1 x = foo(x) print(x) 'x' 3 1 2 none of these
def average_word_length(string): num_words = 0 if not type(string)==str: return "Not a string" if not "A" or not "B" or not "C" or not "D" or not "E" or not "F" or not "G" or not "H" or not "I" or not "J"\ or not "K" or not "L" or not "M" or not "N" or not "O" or not "P" or not "Q" or not "R" or not "S" or not "T"\ or not "U" or not "V" or not...
need help on all parts please and thank you (e) What is the correct output of this code? (2 pts) >>> def func(x): >>> res = 0 >>> for i in range (len (x)): res i >>> return res >>> print (func(4)) ( 4 5 ) 6 ()7 ( What could be described as an immutable list? (2 pts) () a dimple ( ) a tuple ( ) a truffle () a dictionary (g) What is the result of the...
VERSION 0000000 1 Question 14 [2.5 marks] What is the output of the following code fragment? value 0 for i in range (0, 25, 10) : print (value, end-" ") for j in range (0, 10, 5): value + 1 print ('final value', value ) (a) 0 2 4 final value 6 (b) 0 2 4 6 final value 8 (c) 0 3 6 final value 9 (d) 0 3 6 9 final value 12 (e) None of the above.
Im getting the same output but I'm assuming I'm forgetting to incorporate the objective of evaluating in increments of 1 unit? How do I code that? Instructions from your Teacher: run tests Write a program that prints to three significant figures the values of f(x) from x = 0 to x = 10 in increments of 1 unit. The values of x include 0 and 10. The function f(x) is defined below.. 1 import math 2 # funtion g(x) returns...
Question 18 CLO3 Analyze the following code and answer the questions that follow def F(n): If n <= 1: return n else: return F(n-1)+F(n-2) for i in range (n) print (F(i)) Result: 0 1 1 2 3 5 8 13 a. Write number of operations as a function when the code is execute b If n 7, what is the total number of operations? c. What is the complexity of the algorithm behind the code? (2 Marks) (2 Marks) (1...
this python code below is to find the longest common subsequence from two input string !!! however it give me the wrong answer, can any one fix it thanks def lcs(s1, s2): matrix = [["" for x in range(len(s2))] for x in range(len(s1))] for i in range(len(s1)): for j in range(len(s2)): if s1[i] == s2[j]: if i == 0 or j == 0: matrix[i][j] = s1[i] else: matrix[i][j] = matrix[i-1][j-1] + s1[i] else: matrix[i][j] = max(matrix[i-1][j], matrix[i][j-1], key=len) cs =...
Please, I need help debuuging my code. Sample output is below MINN = 1 MAXX = 100 #gets an integer def getValidInt(MINN, MAXX): message = "Enter an integer between" + str(MINN) + "and" + str(MAXX)+ "(inclusive): "#message to ask the user num = int(input(message)) while num < MINN or num > MAXX: print("Invalid choice!") num = int(input(message)) #return result return num #counts dupes def twoInARow(numbers): ans = "No duplicates next to each...