Hi, Looking for some help with this Python question as follows:
Consider the following Python program:
def fun(x, y):
return x * y
a = fun(2, 3)
b = fun("2", 3)
print(a, b)
What does the function evaluate to? What would happen if we replace the last statement print a, b with print a + b?
Thanks for any help.
John
def fun(x, y):
return x * y
a = fun(2, 3)
b = fun("2", 3)
print(a, b)
here a will become 2*3 i.e. 6
b will become "2"*3 i.e. repeat string 2 three times.Hence "222".
Hence function will multiply x by y if it is number .But if is string it just append x to itself y times.
What would happen if we replace the last statement print a, b with print a + b?
It will give error because we cant just add int and string
Output of above is
(6, '222')
Hi, Looking for some help with this Python question as follows: Consider the following Python program:...
Consider the following Python program: def fun(x, y): return x + y # [2] # [1] a = fun(2, 3) b = fun("2", 3) print a, b What does it evaluate to? Replace the last statement print a, b with print a + b and explain the traceback. What's wrong? Now eliminate the line marked [1] and change line [2] to read return x + y. Run the program and explain the traceback. Consider the following definition: def fun(n, m):...
Hi, I need some help finishing the last part of this Python 1 code. The last few functions are incomplete. Thank you. The instructions were: The program has three functions in it. I’ve written all of break_into_list_of_words()--DO NOT CHANGE THIS ONE. All it does is break the very long poem into a list of individual words. Some of what it's doing will not make much sense to you until we get to the strings chapter, and that's fine--that's part of...
Please help on my homework Q i got wrong: PYTHON Question 1 def higherOrderFilter(data, p) : res = [] for d in data : if p(d) : res.append(d) return res def FilterR(data, p): if data == []: return [] return [data[0]] + FilterR(data[1:], p) if p(data[0]) else FilterR(data[1:], p) Both of these functions produce the same output given the same data and same filtering condition p. True False Question 2...
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
Need some help doing and writing this project in python. The purpose of this assignment is to assess your ability to Evaluate properties of modular arithmetic relations Utilize modular arithmetic to encrypt and decrypt plain text Research the Vigenere cipher. Write a program that contains an encode and a decode function. The encode function should take a plaintext message and a key. It should return the encoded message. The decode function should take the encoded message and the key and...
Greeting! Kindly help me to solve my finals in PYTHON, I don't have a knowledge in PYTHON, new student. Please, please, I'm begging, Kindly answers all the questions. I'm hoping to grant my request. Thanks in advanced. 1.) What is the output of the following snippet? l1 = [1,2] for v in range(2): l1.insert(-1,l1[v]) print(l1) a.) [1, 2, 2, 2] b.) [1, 1, 1, 2] c.) [1, 2, 1, 2] d.) [1,...
Page 3 of 7 (Python) For each substring in the input string t that matches the regular expression r, the method call re. aub (r, o, t) substitutes the matching substring with the string a. Wwhat is the output? import re print (re.aub (r"l+\d+ " , "$, "be+345jk3726-45+9xyz")) a. "be$jk3726-455xyz" c. "bejkxyz" 9. b. "be$jks-$$xyz" d. $$$" A object a- A (2) 10. (Python) What is the output? # Source code file: A.py class A init (self, the x): self.x-...
1. Create a Python script file called Assignment_Ch06-02_yourLastName.py. (Replace yourLastName with your last name.) 2. Write a Python program that prompts the user for a sentence, then replaces all the vowels in the sentence with an asterisk: '*' Your program should use/call your isVowel function from Assignment_Ch06-01. You can put the isVowel() function in a separate .py file, without the rest of the Ch06-01 code, and then import it. 6-01 CODE: def isVowel(x): if x in "aeiouyAEIOUY": return True else:...
Write the proposed program in Java, JavaScript, and Python. Run them and compare the results. Submit source code for 3 programs. Let the function fun be defined as int fun(int* k) { *k += 4; return 3 * (*k) - 1; } Suppose fun is used in a program as follows: void main() { int i = 10, j = 10, sum1, sum2; sum1 = (i / 2) + fun(&i); sum2 = fun(&j) + (j / 2); }
Hi, This question is from python unit Q2. Booleans and testing (a) Define the following function. 4 marks def valid(x, y, z): #valid takes three numbers and it returns True iff #at least one of them is positive and at most one of them is negative (b) Define the following function. 6 marks def test_valid(): #test_valid returns True iff valid is correct test_valid should perform a set of well-chosen tests on valid, with at least eight tests.