Quiz for "Learning Python for PL/SQL Developers: Part 1"

Version 1

    Quiz for "Learning Python for PL/SQL Developers: Part 1"

     

    by Arup Nanda

     

    Questions

     

    1. What will be outcome of the following Python program when it's run?

     

    n1 = 1 
    n2 = 2
    print (n2>n1)

     

    Will it produce an error, or an actual output?

     

    2. What will be the output of the following Python program? If it is illegal, then say so.

     

     

    c1 = 'I am a true character' 
    print (2*c1)

     

    3. What will be the output of the following program?

     

     

    c1 = (1,2,3) 
    type (c1)

     

    4. What will be result of the following program?

     

     

    c1 = (1,2,3) 
    print (c1[0])

     

    5. What will be the output of the following?

     

     

    c1 = (1,2,3) 
    print (c1[-2])

     

    6. What will be the output of the following?

     

     

    c1 = (1,2,3) 
    c1.append(4)
    print(c1)

     

    7. You want to print the value of pi and wrote the following program. Is it correct?

     

           

    pi = 3.1416 
    print('Pi = ' + 3.1416)

     

    Answers

     

     

         
    1. True. It's a boolean value. It's legal to print a boolean value. 
    2.    
    3. I am a true characterI am a true character. It's repeated twice.
    4.    
    5. <class 'tuple'>. Note it has parentheses; hence, it is a tuple. 
    6.    
    7. 1. It's the first element.
    8.    
    9. 2, since it's the element in the cell whose left edge is third from the right. Remember, the index starts with 0.
    10.    
    11. It will fail with an error since tuple variables can't be modified. It's a tuple because the elements are enclosed within parentheses.
    12.    
    13. It will result in an error. Unlike PL/SQL, Python doesn't implicitly convert numbers to strings. You have to write the print statement like this: print('Pi = ' + str(3.1416)) 
    14.  

    Back to the Part 1 article.

     

     

    About the Author

     

     

    Arup Nanda (arup@proligence.com has been an Oracle DBA since 1993, handling all aspects of database administration, from performance tuning to security and disaster recovery. He was Oracle Magazine's DBA of the Year in 2003 and received an Oracle Excellence Award for Technologist of the Year in 2012.