Term 3 Test

Name: Surname: Date: . Save your answered form as a PDF file with name "Test-Term3-T1-G10.pdf" and submit it as an attachment via Email to msantos@dragonacademy.org.

This test consists in two parts: a quiz with questions and a coding part with problems.

Quiz (K|C|A)

Write your answer in the corresponding textboxes or choose the rigth radio buttons/checkboxes.

  1. What will be shown by the following code fragment
    
    x = 2 
    y = 2 
    if  x > y  : print("True") 
    else :  print("False")
    
    					
    True
    False
    None
    Will print an error message
  2. What will be shown by the following code fragment
    
    x = "Monday" 
    y = "Monday" 
    if  x == y   :
    	print("True") 
    else :
    	print("False") 
    
    
    					
    True
    False
    None
    Will print an error message
  3. What will be shown by the following code fragment
    					
    						x = 2 
    						if  x == 2   :
    							print("True") 
    						
    					
    					
    True
    False
    Nothing
    Will print an error message
  4. What will be shown by the following code fragment
    
    x = 3 
    if  x == 2   :
    	print("True") 
    
    
    					
    True
    False
    Nothing
    Will print an error message
  5. Enter the value that will be shown by the following code fragment.
    
    x = 3  
    y = 10 
    if x > 0:
       y = 12
    
    y = y + 5 
    print(y) 
    
    						
  6. Enter the value that will be shown by the following code fragment.
    
    x = -3 
    y = 10 
    if x > 0:
       y = 12 
    
    y = y + 5 
    print(y) 
    
    						
  7. Enter the value that will be shown by the following code fragment.
    
    x = -3 
    y = 10  
    if  x > 0   :
       y = 12 
       y = y + 5 
    
    print(y) 
    
    						
  8. Select the values of x for which the following code will produce the value "yes". There may be more than one correct choice.
    
    if  not (x < 5)   :
    	print("yes") 
    
    else :
    	print("No") 
    
    
    						
    3
    5
    10
    50
  9. Select the values of y for which the following code will produce the value "No". There may be more than one correct choice.
    
    						def choose(x):
    							if  (x < 5) or (x > 90)  :
    							  return "yes"
    							
    							else :
    							  return "No" 
    							
    						
    						print( choose(y) ) 
    						
    						
    3
    5
    10
    100

Programming in Python

  1. Write a function that takes one argument 'n' (say 7) and returns the value of the following sum: 1+2+22+23+24+25+26+27. Also, write as a comment the answer you get.
  2. Write a function that take one argument 'n' (say 5) and calculates the following sum: 0 + 20+ 2*21+ 3*22+ 4*23+ 5*24+ 6*25. Also, write as a comment the answer you get.
  3. Somebody scrambled our code. Reorder the different lines of code shown here so that you end up with a program that shows in order the following messages: "Happy birthday to you" (twice), "Happy birthday dear Julia", "Happy birthday to you". Notice: You cannot remove anything and all text below must be used in the final program
  4. Write a function that prompts the user to guess a number. If it is correct, show the message "Correct!". If the guess is not right, print the message "Sorry. Incorrect guess.". You have to choose the hidden number yourself.
  5. Write a function that prompts the user to guess a number. This time we will give the user 3 posibilities to guess it right. At any time, if the guess is correct, show a message saying so. If a guess is larger than the hidden number the program must print "It's smaller!" if a guess is smaller than the right number, the program must print "It's larger!". If after the third try the guess is not right, show the message "Game over.". You have to choose the hidden number yourself.