Advertisement

Python Quiz - 1

1.    What will the following program print out :

>>> x=15           

>>> = x+5           

>>> print(x)       


A.    5

B.    15

C.    20

D.    x+5


Ans :    20                                          


2.    Python scripts (files) have names that end with :


A.    .doc

B.    .exe

C.    .py

D.    .png


Ans :    .py                                         


3.    Which of these words are reserved words in python ?


A.    concat

B.    if & break

C.    todo 

D.    machine


Ans :    if & break                                


4.    What is the proper way to say "good bye" to pyton ?


A.    quit()

B.    while 

C.    #exit

D.    // stop


Ans :    quit()                                        


5.    Which of the parts of a computer actually executes the program instructions ?


A.    Central Processing Unit 

B.    Input/Output Devices

C.    Secondary Memory

D.    Main Momary


Ans :    Central Processing Unit             


6.    A USB memory stick is an example of which of the following components of computer architecture ?


A.    Central Processing Unit

B.    Main Memory

C.    Secondary  Memory

D.    Output Device


Ans :    Secondary Memory                      


7.    What is the best way t think about a " Syntax Error " while programing ?


A.    The computer did not understand the statement that you entered 

B.    The computer has used GPS to find your location and hates everyone from your town 

C.    The computer needs to have uts software upgraded 

D.    The computer is overheating and just wants you to stop to let it cool down 


Ans :     The computer did not understand the statement that you entered           


8.    Which of the following is a comment in python ?


A.    *This is a test

B.    /*This is a test*/ 

C.    #This is a test 

D.    //This is a test


Ans :    #This is a test                         


9.    In the following code,

x =42                    

       What is "x" ?       


A.    A Centeral Processing Unit

B.    A function 

C.    A constant 

D.    A variable


Ans :    A variable                               


10.   Which of the following is not a Python reserved word ?


A.    spam 

B.    break

C.    continue

D.    for


Ans :    spam                                       


11.   Which of the following elements of a mathematical expression in Python is evaluated first ?


A.    Multiplication *

B.    Subtraction -

C.    Parentheses ( )

D.    Addition +


Ans :    Parentheses ( )                       


12.   What is the value of the following expression :

42 % 10                                                        

        Hint - the "%" is the remainder operator 


A.    10

B.    2

C.    0.42

D.    4210


Ans :    2                                            


13.   What will be the value of x after the following statement executes :

x = 1+ 2 * 3 - 8 / 4    


A.    1.0

B.    3

C.    2

D.    5.0


Ans :    5.0                                         


14.   What will be the value of x when the following statement is executed :

X = int ( 98.6 )    


A.    99

B.    98

C.    100

D.    6


Ans :    98                                         


15.   What does the Python input () function do ?


A.    Pause the program and read data from the user

B.    Connect to the network and retrieve a web page

C.    Read the memory of the running program

D.    Take a screen shot from an area of the screen 


Ans :    Pause the program and read data from the user      


16.   Which of these operators is not a comparison / logical operator ?


A.    =

B.    !=

C.    <=

D.    >=


Ans :    =                                      


17.    What is true about the following code segment :

if x == 5 :                    

print('Is 5')                 

print('Is Still 5')         

print('Third 5')          


A.    Depending on the value of x either all three of the print statements will execute or none of the statements will execute.

B.    The string 'Is 5' will always print out regardless of the value for x.

C.    The string 'Is 5 ' will never print out regardless of the value for x.

D.    Only two of the three print statements will print out if the value of x is less than zero.


Ans :    Depending on the value of x either all three of the print statements will execute or none of the statements will execute.  


18.   When you have multiple lines in an if block, how do you indicate the end of the if block ?


A.    You use a curly brace (after the last line of the if block 

B.    You de-indent the next line past the if block to the same level of indent as the original if statement 

C.    You omit the semicolon ; on the last line of the if block

D.    You capitalize the firsst letter of the line following the end of the block


Ans :    You de-indent the next line past the if block to the same level of indent as the original if statement     


19.    What is the Python reserved word that we use in two way if tests to indicate the block of code that is to be executed if the logical test is false ?


A.    iterate

B.    break 

C.    else

D.    Except


Ans :    else                                      


20.   What will the following code print out ?

x= 0                             

if x < 2 :                      

    print('small')          

elif x<10 :                    

    print('Medium')     

else :                            

    print('LARGE')     

print('All done')          


A.    Small, All done

B.    All done

C.    Small, Medium, LARGE, All done

D.    LARGE, All done


Ans :    Small, All done                        

   

           

Post a Comment

0 Comments