Preview

01 - Python (Foundation)

 1. Which of the following is correct about Python?

  It uses English keywords frequently where as other languages use punctuation.

  Python is a high-level, interpreted, interactive and object-oriented scripting language.

  All the answers listed in this selection are correct.

  Python is designed to be highly readable.

 2. Which of the following statements are correct, in reference to the following code?
def letterGrade(score):
    if score >= 90:
        letter = 'A'
    else:   # grade must be B, C, D or F
        if score >= 80:
            letter = 'B'
        else:  # grade must be C, D or F
            if score >= 70:
                letter = 'C'
            else:    # grade must D or F
                if score >= 60:
                    letter = 'D'
                else:
                    letter = 'F'
    return letter

  The name of the function is letterGrade and it has two variables in use; score and letter

  In this code, 'score' is a function that is being passed to the variable 'letterGrade'

  The name of the variables in the function include letter,score and grade

  This function uses variables that are both strings and integers and therefore goes against python rules

 3. Python is a case sensitive language?

  FALSE

  TRUE

 4. Which of the following is NOT a data type in Python?

  Slice

  List

  Integer

  String

 5. What is the output of print(str) if str = 'Hello World!'?

  Error

  Hello World!

  11

  str

 6. What is happening on line 2 of the following code?
age = input("Enter your age: ")
age = int(age)

  casting (converting age - which is input as a string - into an integer)

  checking to see if the variable 'age' is an int (integer)

  checking to see if the variable 'int' is age related

  casting (converting age into a string)

 7. The following examples are examples of string ________________.
print("Test" + "Track")
print("Door" + "man")
print("4" + "chan")

  concatenation

  addition

  errors

  correlation

 8. What is the output of the following code?
print(4 * "me")

 9. The following code should take an input (an integer) and output whether it is odd or even. What is the output if the input given is the number '2'?
num = input("Enter a number: ")
mod = num * 2
if mod > 0:
    print("You picked an odd number.")
else:
    print("You picked an even number.")

  You piked an odd number AND you picked an even number

  You picked an odd number

  You picked an even number

  Error

 10. In order for the code above to output 'You have picked an even number' when the input '20' is entered, what needs to change?

  Line 1 needs to be changed to: num = odd or even ("Enter a number")

  Nothing, the code works perfectly.

  Line 3 needs to be change d to if mod < 0:

  Line 2 needs to be changed to use MOD e.g. mod = num % 2

 11. What is the output of the following code?
mylist=[1,2,3,64,75,22]
print(mylist[2]*2)

 12. Syntax errors in python are detected by the _________at _______

  interpreter / before the code is written

  compiler / compile time

  assembler / run time

   interpreter/ run time

 13. Which of the following statements explains WHY the output of this code is 300?
balance=300
if balance < 0:
    transfer = -balance
    backupAccount = backupAccount - transfer
    balance = balance + transfer
print(balance)

  Because the condition outlined in the if statement on line 2 is true

  Because there is an error on line 1 and 5

  Because the condition outlined on line 2 is not true so that part of code does not run

  Because the transfer amount is always 0, which means 300+0 = 300

 14. The following code snippet seeks to print out "The count is: 0; The count is: 1; The count is 2; all the way up to The count is 8. What is missing from line 4?
count = 0
while (count < 9):
   print 'The count is:', count
   ???????????????????????

print "Good bye!"

  count = count - 1

  count = count + 1

  count/0

  count = 0 + 1

 15. Which of the following statements is true of this code?
while True:
    print("hello world")

  It will print the word "true" to the screen before it prints "Hello World"

  It will print "hello world" once

  It is an infinite loop

  It will only print "hello world" if the input is "true"