python Assignment with Answer, Assignments of Programming Languages

python programming Assignment solved with Answer.

Typology: Assignments

2020/2021

Uploaded on 02/07/2021

Mantu96
Mantu96 🇮🇳

5

(1)

3 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1 What is the result of the snippet of code
shown below if x=1? x<<2
a) 8
b) 1
c) 2
d) 4
Ans:(d)4
2 The output of the expression is: bin(29)
a) ‘0b10111’
b) ‘0b11101’
c) ‘0b11111’
d) ‘0b11011’
Ans:(b)‘0b11101’
3 What is the value of x if: x>>2=2
a) 8
b) 4
c) 2
d) 1
Ans:(a)8
4. What is the result of the expression:
int(1011)?
a) 1011
b) 11
c) 13
c) 1101
Ans:(a) 1011
5 To find the decimal value of 1111, that is 15,
we can use the function:
a) int(1111,10)
b) int(‘1111’,10)
c) int(1111,2)
d) int(‘1111’,2)
Ans:(d) int(‘1111’,2)
6 What is the result of the expression if x=15
and y=12: x & y
a) b1101
b) 0b1101
c) 12
d) 1101
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download python Assignment with Answer and more Assignments Programming Languages in PDF only on Docsity!

1 What is the result of the snippet of code shown below if x=1? x<< a) 8 b) 1 c) 2 d) 4 Ans:(d) 2 The output of the expression is: bin(29) a) ‘0b10111’ b) ‘0b11101’ c) ‘0b11111’ d) ‘0b11011’ Ans:(b)‘0b11101’ 3 What is the value of x if: x>>2= a) 8 b) 4 c) 2 d) 1 Ans:(a)

  1. What is the result of the expression: int(1011)? a) 1011 b) 11 c) 13 c) 1101 Ans:(a) 1011 5 To find the decimal value of 1111, that is 15, we can use the function: a) int(1111,10) b) int(‘1111’,10) c) int(1111,2) d) int(‘1111’,2) Ans:(d) int(‘1111’,2) 6 What is the result of the expression if x= and y=12: x & y a) b b) 0b c) 12 d) 1101

Ans:(c) 12

  1. Which of the following expressions results in an error? a) int(1011) b) int(‘1011’,23) c) int(1011,2) d) int(‘1011’) Ans:(c) int(1011,2)
  2. Which of the following represents the bitwise XOR operator? a) & b) ^ c) | d)! Ans:(b) ^
  3. What is the value of this expression? bin(0x8) a) ‘0bx1000’ b) 8 c) 1000 d) ‘0b1000’ Ans:(d) ‘0b1000’
  4. What is the result of the expression: 0x35 | 0x a) 115 b) 116 c) 117 d) 118 Ans:(c) 117
  5. It is not possible for the two’s complement value to be equal to the original value in any case. State whether this statement is true or false. a) True b) False Ans:(b) False
  6. The one’s complement of 110010101 is: a) 001101010 b) 110010101

Ans:(a) a<<

  1. What is the output of the code show below if a=10 and b =20? a= b= a=a^b b=a^b a=a^b print(a,b) a) 10 20 b) 10 10 c) 20 10 d) 20 20 Ans:(c) 20 10
  2. What is the two’s complement of -44? a) 1011011 b) 11010100 c) 11101011 d) 10110011 Ans:(b) 11010100
  3. What is the value of the expression: ~100? a) 101 b) - c) 100 d) - Ans:(b) -
  4. What is the output of the code shown below? l=[1, 0, 2, 0, 'hello', '', []] list(filter(bool, l)) a) Error b) [1, 0, 2, 0, ‘hello’, ”, []] c) [1, 0, 2, ‘hello’, ”, []] d) [1, 2, ‘hello’] Ans:(d) [1, 2, ‘hello’]
  5. What is the output of the code shown below? if (9 < 0) and (0 < -9): print("hello")

elif (9 > 0) or False: print("good") else: print("bad") a) error b) hello c) good d) bad Ans:(c) good

  1. The output of the line of code shown below is: not(10<20) and not(10>30) a) True b) False c) Error d) No output Ans:(b) False
  2. The output of the snippet of code shown below? bool(‘False’) bool() a) True True b) False True c) False False d) True False Ans:(d) True False
  3. What is the output of the snippet of code shown below? ['hello', 'morning'][bool('')] a) error b) no output c) hello d) morning Ans:(c) hello
  4. In python we do not specify types; it is directly interpreted by the compiler, so consider the following operation to be performed. 1.>>>x = 13? 2 objectives is to make sure x has a integer value, select all that apply (python 3.xx) a) x = 13 // 2 b) x = int(13 / 2) c) x = 13 % 2 d) All of the mentioned Ans:(d) All of the mentioned

d) ”’That’s okay”’ Ans:(c) ‘3\’

  1. The following is displayed by a print function call: 1.tom 2.dick 3.harry Select all of the function calls that result in this output a) print(”’tom \ndick \nharry”’) b) print(”’tomdickharry”’) c) print(‘tom\ndick\nharry’) d) print(‘tom dick harry’) Ans:(c) print(‘tom\ndick\nharry’)
  2. What is the average value of the code that is executed below? 1.>>>grade1 = 80 2.>>>grade2 = 90 3.>>>average = (grade1 + grade2) / 2 a) 85 b) 85. c) 95 d) 95. Ans:(a) 85
  3. Select all options that print hello-how-are-you a) print(‘hello’, ‘how’, ‘are’, ‘you’) b) print(‘hello’, ‘how’, ‘are’, ‘you’ + ‘-‘ * 4) c) print(‘hello-‘ + ‘how-are-you’)* d) print(‘hello’ + ‘-‘ + ‘how’ + ‘-‘ + ‘are’ + ‘you’) Ans:(c) print(‘hello-‘ + ‘how-are-you’)*
  4. What is the return value of trunc()? a) int b) bool c) float

d) None Ans:(a) int

  1. What is the output of print 0.1 + 0.2 == 0.3? a) True b) False c) Machine dependent d) Error Ans:(b) False
  2. Which of the following is not a complex number? a) k = 2 + 3j b) k = complex(2, 3) c) k = 2 + 3l d) k = 2 + 3J Ans:(c) k = 2 + 3l
  3. What is the type of inf? a) Boolean b) Integer c) Float d) Complex Ans:c) Float
  4. What does ~4 evaluate to? a) - b) - c) - d) + Ans:a) -
  5. What does ~~~~~~5 evaluate to? a) + b) - c) + d) - Ans:a) +
  6. Which of the following is incorrect? a) x = 0b b) x = 0x4f c) x = 19023 d) x = 03964 Ans:d) x = 03964

Ans:(d) **

  1. What is the value of x if: x = int(43.55+2/2) a) 43 b) 44 c) 22 d) 23 Ans:(b) 44