Question

Greeting! Kindly help me to solve my finals in PYTHON, I don't have a knowledge in...

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, 1, 1, 2]


2.) The meaning of a positional argument is determined by:

       a.) its position within the argument list
       b.) its value
       c.) its connection with existing variables
       d.) the argument’s name specified along with its value


3.) Which of the following sentences are true? Choose all that apply.

nums = [1,2,3]
vals = nums

       a.) nums and vals are different lists
       b.) vals is longer than nums
       c.) nums and vals are different names of the same list
       d.) nums is longer than vals


4.) An operator able to check whether two values are not equal is coded as:

       a.) <>
       b.) !=
       c.) =/=
       d.) not ==

5.) The following snippet:


def func1(a):
return None
def func2(a):
return func1(a)*func1(a)
print(func2(2))

       a.) will output 4
       b.) will output 2
       c.) will cause a runtime error
       d.) will output 16


6.) The result of the following division:


1 // 2

       a.) is equal to 0.0
       b.) cannot be predicted
       c.) is equal to 0.5
       d.) is equal to 0


7.) The following snippet:


    def func(a,b):
        return b ** a  
    print(func(b=2,2))

       a.) will output 2
       b.) is erroneous
       c.) will return None
       d.) will output 4


8.) What value will be assigned to the x variable?

    z = 0
    y = 10
    x = y < z and z > y or y > z and z < y

       a.) 1
       b.) False
       c.) True
       d.) 0

9.) One of the following variables’ names is illegal – which one?

       a.) in_
       b.) in
       c.) In
       d.) IN


10.) What is the output of the following snippet?


    list = [x*x for x in range(5)]
    def fun(L):
        del L[L[2]]
        return L
  
    print(fun(list))

       a.) [0, 1, 4, 16]
       b.) [0, 1, 4, 9]
       c.) [1, 4, 9, 16]
       d.) [0, 1, 4, 16]


11.) What is the output of the following piece of code?


    x=1
    y=2
    x, y, z = x, x, y
    z, y, z = x, y, z
    print(x,y,z)

       a.) 2 1 2
       b.) 1 2 1
       c.) 1 1 2
       d.) 1 2 2

12.) What will the output of the following snippet?


    a = 1
    b = 0
    a = a ^ b
    b = a ^ b
    a = a ^ b
    print(a,b)

       a.) 0 1
       b.) 0 0
       c.) 1 1
       d.) 1 0

13.) What is the output of the following snippet?


    def fun(x):
        if x % 2 == 0:
            return 1
        else:
            return 2
  
    print(fun(fun(2)))


       a.) the code will cause a runtime error
       b.) 1
       c.) 2
       d.) None

14.) Take a look at the snippet and choose the true statement:


    nums = [1,2,3]
    vals = nums
    del vals[:]

       a.) vals is longer than nums
       b.) the snippet will cause a runtime error
       c.) nums and vals are different names of the same list
       d.) nums and vals are different lists


15.) What is the output of the following piece of code if the user enters two lines containing 3 and 2 respectively?


    x=int(input())
    y=int(input())
    x = x % y
    x = x % y
    y = y % x
    print(y)


       a.) 0
       b.) 2
       c.) 3
       d.) 1

16.) What is the output of the following piece of code if the user enters two lines containing 3 and 6 respectively?


    y=input()
    x=input()
    print(x+y)

       a.) 36
       b.) 3
       c.) 63
       d.) 6


17.) What is the output of the following piece of code?


    print("a","b","c",sep="sep")

       a.) asepbsepc
       b.) asepbsepcsep
       c.) abc
       d.) a b c

18.)What is the output of the following piece of code?


    X = 1 // 5 + 1 / 5
    print(X)

       a.) 0.2
       b.) 0.0
       c.) 0.4
       d.) 0


19.) Assuming that the tuple is a correctly created tuple, the fact that tuples are immutable means that the following instruction:


    tuple[1] = tuple[1] + tuple[0]

       a.) can be executed if and only if the tuple contains at least two elements
       b.) is fully correct
       c.) is illegal
       d.) may be illegal if the tuple contains strings

20.) What is the output of the following piece of code if the user enters two lines containing 2 and 4 respectively?


    x=float(input())
    y=float(input())
    print(y ** (1/x))

       a.) 1.0
       b.) 4.0
       c.) 0.0
       d.) 2.0


21.) What is the output of the following snippet?


    dct = { 'one':'two', 'three':'one', 'two':'three' }
    v = dct['three']
    for k in range(len(dct)):
        v = dct[v]
    print(v)

       a.) two
       b.) three
       c.) one
       d.) ('one', 'two', 'three')


22.) How many elements does the L list contain?


    L = [i for i in range(-1,-2)]

       a.) 2
       b.) 3
       c.) 1
       d.) 0

23.)Which of the following lines improperly invokes the function defined as:


def fun(a,b,c=0)
Choose all that apply.

       a.) fun(b=1):
       b.) fun(a=1,b=0,c=0):
       c.) fun(0,1,2):
       d.) fun(a=0,b=0):


24.) What is the output of the following snippet?


    def fun(x,y):
        if x == y:
            return x
        else:
            return fun(x,y-1)
  
    print(fun(0,3))

       a.) 1
       b.) the snippet will cause a runtime error
       c.) 2
       d.) 0


25.) How many stars will the following snippet send to the console?


    i = 0
    while i < i + 2 :
        i += 1  
        print("*")
    else:
        print("*")


       a.) zero
       b.) the snippet will enter an infinite loop
       c.) two
       d.) one

26.) What is the output of the following snippet?


    tup = (1, 2, 4, 8)
    tup = tup[-2:-1]
    tup = tup[-1]
    print(tup)


       a.) (4,)
       b.) 44
       c.) (4)
       d.) 4


27.) What is the output of the following snippet?


    dd = { "1":"0", "0":"1" }
    for x in dd.vals():
        print(x,end="")

       a.) 0 0
       b.) 1 0
       c.) the code is erroneous
       d.) 0 1

28.) What is the output of the following snippet?


    dct = {}
    dct['1'] = (1,2)
    dct['2'] = (2,1)
    for x in dct.keys():
        print(dct[x][1],end="")

       a.) 12
       b.) 21
       c.) (1,2)
       d.) (2,1)

29.) What is the output of the following snippet?


    def fun(inp=2,out=3):
        return inp * out
    print(fun(out=2))

       a.) 6
       b.) 2
       c.) the snippet is erroneous
       d.) 4

30.) How many hashes will the following snippet send to the console?


    lst = [[x for x in range(3)] for y in range(3)]
    for r in range(3):
        for c in range(3):
            if lst[r][c] % 2 != 0:
                print("#")

           a.) six
           b.) zero
           c.) nine
           d.) three

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

1)

Output

[1,1,1,2]

We have initial list as [1,2] -> 1 at 0 and 2 at 1 position

Now a for loop which will run 2 times

l1.insert(-1,l1[v])

This statement will insert value at l1[v] at position -1

For v = 1

It will insert 1 at -1 i.e. at starting of list

List becomes [1,1,2]

For v = 2

It will insert 1 at -1 i.e. at starting of list

List becomes [1,1,1,2]

2)

the argument’s name specified along with its value

3)

var = nums

Doing so makes different names refer to same list

4)

Not equal to operator is !=

5)

This will cause runtime error

Reason - None is not supported type for * operator

6)

// is division operator and it will result in 0

7)

This code is erroneous as

Either we pass both values, else if we are passing with argument name then need to pass all arguments with name

The correct way is print(func(b=2,a=2))

8)

True

We have z = 0

y = 10

Now x = y < z and z > y or y > z and z < y

y<z

10<0, this is false

z>y

0>10, this is false

y>z

10>0, this is true

z<y

0<10, this is true

x = false and false or true and true

x = false or true

x = true

9)

in

As this is a predefined operator in python (Category - Comparisons, Identity, Membership operators)

10)

By first statement

list = [x*x for x in range(5)]

x = 0

list gets value 0

x = 1

list gets value 1*1

x = 2

list gets value 2*2

x = 3

list gets value 3*3

x = 4

list gets value 4*4

So list = [0,1,4,9,16]

Now we have function fun(L)

Where we are deleting

del L[L[2]] i.e. element at position 2 which is 4

del L[4] i.e. element at position 4 which is 16

del 16

Now list becomes [0,1,4,9]

return this and print

11)

We have

x=1

y=2

x, y, z = x, x, y

z, y, z = x, y, z

Now in above declaration we can see

x, y, z = x,x,y

So here all values gets assigned in order

x = 1 (value of x)

y = 1 (value of x)

z = 2 (value of y)

z,y,z = x,y,z

z = 1 (value of x)

y = 1 (value of y)

z = 2 (value of z)

So final values are x = 1, y = 1, z = 2

12)

We have

a = 1

b = 0

Now ^ is bitwise XOR (which is 1 if both values are different else 0)

a = a^b

a = 1^0

a = 1

b = a ^b

b = 1 ^ 0

b = 1

a = a ^ b

a = 1 ^ 1

a = 0

Final values are 0 1

13)

Here we are printing as

print(fun(fun(2))

So first fun(2) will be called

Inside fun we have if x%2==0

2%2==0 which is true so it will return 1

Now we have fun(1)

Inside fun we have

if x%2 == 0

1 % 2 == 0 false

So control will go to else

and it will return 2

Hence the code will print 2

14)

nums and vals are different list

With vals = num, they are pointing to same list

But with del vals[:], vals will become empty hence different list

15)

With input 3 and 2

x = 3

y = 2

x = x % y

x = 3 % 2

x = 1

x = x % y

x = 1 % 2

x = 1

y = y % x

y = 2 % 1

y = 0

16)

With input 3 and 6

x = 3

y = 6

print(x+y)

print(3+6)

36 // As the input are string and not converted to int so + will work as concatenation operator

17)

This will print asepbsepc

As in print we have sep="sep" this means the separation which is space should be replaced with sep

18)

X = 1 // 5 + 1 / 5

1//5 is 0 (// is floor division operator hence will not give decimal values)

1/5 = 0.2

0 + 0.2

0.2

20)

With user entering 2 and 4

x = 2

y = 4

print(y **(1/x))

print(y ** (1/2))

print(y ** 0.5)

print(2 ** 0.5) {** is exponent operator, power calculation)

2.0

21)

We have dictionary where

one - two

three - one

two - three

Now we are assigning v = dct['three']

v = one {three-one}

We have for loop which runs 3 times (length of dict)

1) v = dct[v]

v = dct[one]

v = two

2) v = dct[v]

v = dct[two]

v = three

3)

v = dct[v]

v = dct[three]

v = one

22)

This will be an empty list with len 0

As we are looping within range - 1 and -2 , hence i = -1

And this is not a valid range for list

23)

fun(b=1)

Here the function is expecting positional argument a as well, (c is already defined in function list)

24)

With calling fun(0,3)

We get x = 0

y = 3

Now if x==y

0==3 is false

Control goes to else which calls fun(0,2) {y-1}

We get x = 0

y = 2

Now if x==y

0==2 is false

Control goes to else which calls fun(0,1) {y-1}

We get x = 0

y = 1

Now if x==y

0==1 is false

Control goes to else which calls fun(0,0) {y-1}

We get x = 0

y = 0

Now if x==y

0==0 is true

and return x which is 0

25)

This will do in infinite loop as i will always be less than i+2

27)

This is erroneous code as dict(dictionary) does not any attribute called vals

28)

This will print 21

Here dict have keys 1 and 2

At key 1 we have (1,2)

At key 2 we have (2,1)

Now for loop which will iterate for dict keys

dct[x][1]

dct[1][1] is 2

dct[2][1] is 1

29)

This will print 2

We have fun with predefined values inp = 2 and out 3

While calling fun we are passing value of out = 2 and nw out will take this value

hence 2 * 2

Add a comment
Know the answer?
Add Answer to:
Greeting! Kindly help me to solve my finals in PYTHON, I don't have a knowledge in...
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
  • Please help on my homework Q i got wrong: PYTHON Question 1 def higherOrderFilter(data, p) :...

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

  • (Please help me with Coding in Python3) AVLTree complete the following implementation of the balanced (AVL)...

    (Please help me with Coding in Python3) AVLTree complete the following implementation of the balanced (AVL) binary search tree. Note that you should not be implementing the map-based API described in the plain (unbalanced) BSTree notebook — i.e., nodes in the AVLTree will only contain a single value. class AVLTree: class Node: def __init__(self, val, left=None, right=None): self.val = val self.left = left self.right = right def rotate_right(self): n = self.left self.val, n.val = n.val, self.val self.left, n.left, self.right, n.right...

  • need help on all parts please and thank you (e) What is the correct output of...

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

  • for this code fix the smtax error this is a python code for some reason my...

    for this code fix the smtax error this is a python code for some reason my code isnt liking my returns and it bring up other symtax error so fix the following code answer should pop out the following when runned 1/ 2 + 1/ 3 + 1/ 12 = 11/12 z=' ' def math(x,y):     global z     if y==0 or x==0:         return     if y%x ==0:         z=("1/"+str(int(y/x))         return      if x%y ==0         z+=(int(x/y))    ...

  • Python: 1) What output is generated by the following code segment? table = [["T", "U", "V"],...

    Python: 1) What output is generated by the following code segment? table = [["T", "U", "V"], ["W", "X", "Y"]] print(table[0]) Group of answer choices a- T b- ["T", "W"] c- ["T", "U", "V"] d- [["T", "U", "V"], ["W", "X", "Y"]] 2) Consider the following code segment: values = [4, 12, 0, 1, 5] print(values[1]) What is displayed when it runs? Group of answer choices a- 0 b- 1 c- 4 d- 12 3) Consider the following code segment: x =...

  • use python IDEL Please highlight the answer 1 ווCIוסטIT Errors and Exceptions. There are two main...

    use python IDEL Please highlight the answer 1 ווCIוסטIT Errors and Exceptions. There are two main types of errors: syntax errors and runtime errors. Syntax errors are detected by the Python interpreter before the program execution during the parsing stage (parsing is a process, during which the Python interpreter analyzes the grammatical structure of the program). Runtime errors are errors in a program that are not detected by the Python interpreter during its parsing stage. They are further divided into...

  • Consider the following Python program: def fun(x, y): return x + y # [2] # [1]...

    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):...

  • convert the following code from python to java. def topkFrequent(nums, k): if not nums: return [...

    convert the following code from python to java. def topkFrequent(nums, k): if not nums: return [ ] if len(nums) == 1: return nums [0] # first find freq freq dict d = {} for num in nums: if num in d: d[num] -= 1 # reverse the sign on the freq for the heap's sake else: d[num] = -1 h = [] from heapq import heappush, heappop for key in di heappush(h, (d[key], key)) res = [] count = 0...

  • Hi, Looking for some help with this Python question as follows: Consider the following Python program:...

    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

  • 12p I need help this is Python EXCEPTIONS: It's easier to ask forgiveness than permission. Try...

    12p I need help this is Python EXCEPTIONS: It's easier to ask forgiveness than permission. Try the code and catch the errors. The other paradigm is 'Look before you leap' which means test conditions to avoid errors. This can cause race conditions. 1.Write the output of the code here: class MyError(Exception): pass def notZero(num): if num == 0: raise MyError def run(f): try: exec(f) except TypeError: print("Wrong type, Programmer error") except ValueError: print("We value only integers.") except Zero Division Error:...

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