Assessing Skills in Python Syntax & For-Loops

Nov 4, 2013 • Sharon Benjamin

Multiple Choice on Python concepts including basic syntax, for-loop, if-statements, correctly concatenate strings and integers for print statements.

  1. Novice v. competent

Which statement will print the numbers 1, 2, 3, 4, and 5?

  1. for i in range(0,5):
       print i
  2. for i in range(1:6):
    print i
  3. for i in range(1,6):
    print i
  4. for i in range (0:5):
    print i
  5. Competent vs. expert:

Choose the code that will print true statements:

  1. for i in range(0:10):
    if i < 7:
        print i + " is less than 7."
    else:
        print i + " is greater that or equal to 7."
  2. for i in range(0:10):
    if i < 7:
        print str(i) + " is less than 7."
    else
        print str(i) + " is greater that or equal to 7."
  3. for i in range(0,10):
    if i < 7:
        print i + " is less than 7."
    else
        print i + " is greater that or equal to 7."
  4. for i in range(0,10):
    if i < 7:
        print str(i) + " is less than 7."
    else:
        print str(i) + " is greater that or equal to 7."