Posts

Showing posts from June, 2018

PYTHON FAQ-2

  PYTHON FAQ-2 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 2) The output of the expression is: bin(29) a) ‘0b10111’ b) ‘0b11101’ c) ‘0b11111’ d) ‘0b11011’ 3) What is the value of x if: x>>2=2 a) 8 b) 4 c) 2 d) 1 4.) What is the result of the expression: int(1011)? a) 1011 b) 11 c) 13 c) 1101 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) 6) What is the result of the expression if x=15 and y=12: x & y a) b1101 b) 0b1101 c) 12 d) 1101 7. )Which of the following expressions results in an error? a) int(1011) b) int(‘1011’,23) c) int(1011,2) d) int(‘1011’) 8.) Which of the following represents the bitwise XOR operator? a) & b) ^ c) | d) ! 9.) What is the value of this expression? bin(0x8) a) ‘0bx1000’ b) 8 c) 1000 d) ‘0b1000’ 10.) What is the result of the expression: 0x35 | 0x75 a) 115 b) 116 c) 117 d) 118 11.) It is not possi

Python Decision Making and Loops

DECISION MAKING: If Statement        An if statement consists of a boolean expression followed by one or more statements. if...else statement nested if else statement An if statement can be followed by an optional else statement , which executes when the boolean expression is FALSE. You can use one if or else if statement inside another if or else if statement(s). Ex: var = 100      #indentation is important if ( var ==100): print "Good bye!" Else: An else statement can be combined with an if statement. An else statement contains the block of code that executes if the conditional expression in the if statement resolves to 0 or a FALSE value. if expression: statement(s) else: statement(s) 2) a=10 if(a>10):               print("Value of a is greater")   else :                   print("Value of a is 10") 3) var1 = 100 if var1: print "1 - Go