Preview

3 - Create a complete app - covid-19 tracker

 1. _______ refers to the entirety of a computer system or application, comprising both the front end and the back end.

 2. HTML is an example of a back end language.

  FALSE

  TRUE

 3. Decomposition is about breaking a big problem into smaller solvable sub problems. This is an example of _____________.

  modular design

  global variable use

  interpretation

  incrementation

 4. The following is an example of a _________ in python. It contains a number of different fruits.
def fruits():
  fruits=["apple","pear","banana","orange"]
  print(fruits[2])

fruits()

  list

  multiple constant stack

  access variable

  local variable bunch

 5. When the code above is executed (run), the output is: banana. What is the output for the command print(fruits[0])?

  pear

  apple

  banana

  orange

 6. The following code uses several functions. What is the output of this program code when run?
def function1():
  print(1)
  function2()

def function2():
  print(2)
  function3()
  
def function3():
  print(3)

function2()

  1

  1,2,3

  2

  2,3

 7. In Python, a ________ declared outside of the function or in global scope is known as a global variable.

  variable

  program

  syntax error

  global constant

 8. In the following code, we are attempting to modify the variable 'c' insde the function 'add'. What is the output?
c = 1 # global variable
    
def add():
    c = c + 2 # increment c by 2
    print(c)

add()

  Error - because the global variable cannot be modified inside the function

  Error - the global variable can be accessed but cannot be modified inside the function

  All of the options listed here are correct

  Error - local variable c referenced before assignment

 9. Here we have a function named 'foo'. We call the function and try to print the local variable y. Which of the following statements is correct?
def foo():
    y = "local"


foo()
print(y)

  All of the statements listed are correct

  The output shows an error because we are trying to access a local variable y in a global scope

  The local variable 'y' only works inside the function 'foo' - that is, within local scope

  NameError: name 'y' is not defined

 10. In the code below y is a global variable and x is a local variable in the foo function. The ouput is 10 and 3.
x =5

def foo():
    global x
    y = 3
    x = x * 2
    print(x)
    print(y)

foo()

  FALSE

  TRUE

 11. What is the output of the following program? Which of the following statements is correct?
def corona_log():
  print("---Current case count---")
  count=32
  new_covid_case(count)
  
def new_covid_case(count):
  print("---Reporting a new case")
  count=count+1
  print("Updated count:",count)

corona_log()

  

  There will be an error. The variable 'count' is a global variable and cannot be used locally.

  The output is 33. On line 4, the parameter 'count' is being passed to the function new_covid_case.

  There will be an error. The variable 'count' is a local variable and the attempt is being made to use it globally.

  The output is 32. On line 4, the parameter 'count' is being passed to the function new_covid_case.

 12. The programmer wants the output to be "Player has been shot ('Current health critical:', 10)" but instead there is an error. On what line is the error and what needs to be done?
#scoring and health module for a game
def gameplay():
  health=100
  print("Player has been shot")
  health_after_gunshot(health)
  
def health_after_gunshot():
  health=health-90
  print("Current health critical:",health)

gameplay()

  Line 3 - health should be a local variable

  Line 8 - it is not possible to make a variable's value go down. Eg. Health = health - 90 will cause an error.

  Line 5 - the function health_after_gunshot() is being called but the variable is not being passed.

  Line 7 should be: def health_after_gunshot(health):

 13. What is the output of the following program?
#scoring and health module for a game
def gameplay():
  score=30
  collected_star=20
  score_after_star(score)
 
  
def score_after_star(score):
  score=score+50
  print("Updated score:",score)


gameplay()

  ('Updated score:',100)

  ('Updated score:', 80)

  ('Updated score:', 70)

  ('Updated score:', 50)

 14. Decomposition is important in problem solving. It involves breaking down a complex problem into _________________________.

  smaller parts that are more manageable and easier to understand.

  bigger parts that are closer to the original problem itself.

  smaller parts that are unsolvable.

  bigger parts that are still more complex.

 15. Read the following excerpt and fill in the blanks.
A ___________ is commonly used to lay out content and functionality 
on a page which takes into account user needs and user journeys. 
A __________ is used early in the development process to establish 
the basic structure of a webpage or app before visual design and 
content is added.

  wireframe

  debugger

  website

  module

 16. What code should go on line 9 if we wish for the score to go up by 1 if the answer is correct? (incrementation of score)
def quiz():
  score=0
  print("------Quiz Time-----")
  print("Current score",score)
  print("--------------------")
  answer1=input("Donald is the name of a ____________: Write your answer here:")
  if answer1=="duck" or answer1=="American President":
    print("Well done")
    #What should go here to make the score go up by 1?
    print("Updated score:",score)

quiz()

  1 + 1 = score

  score = 1 + 1

  score=score+1

  score = add 1

 17. The following code has two errors that will prevent it from running. What are they?
def add()
print("--The adding app--")
  num1=input("Enter number 1:")
  num2=input("Enter number 2:")
  print(num1+num2)

add()

  Line 2 - incorrect indentation. Line 7 - missing colon.

  Line 3 - missing colon. Line 4 - missing bracket.

  Line 1 - missing colon after add. Line 2 - Indentation error.

  There are no errors

 18. In the following program there is a LOGICAL ERROR. The user enters 3 and then 3, but the output is 33 instead of 6. Why?
def add_numbers():
  print("ADDING APP")
  n1=input("Enter number 1:")
  n2=input("Enter number 2:")
  print(n1+n2)

add_numbers()

  Line 5 should be: print(int(n1)+int(n2)) to make inputs of 3 and 3 equal 6.

  All of the listed options here are correct.

  In line 3 and 4 the input taken is of the string data type. It needs to be cast as integer.

  Line 3 should be n1=int(input(

 19. What is the output of the following program?
def logicfollow():
  a=2
  b=5
  b=b+1
  c=a+1
  d=c+b
  z=a
  print(z+b)
logicfollow()

 20. The three programming constructs are sequence, selection and iteration. Iteration refers to the use of ________.

  lists

  loops

  if statements

  sequential programming (sequence of statements in order)