ELEX 4653 Sample Final Exam 2

Sample final exam. Version 2 (May 17, 9:00 - addd back code in questions).

Instructions:

  • Answer all four (4) questions.

  • You have 110 minutes to complete the exam.

  • This is an open-book exam. All written material is allowed.

  • No electronic devices other than a flash drive and the lab PC may be used during the exam.

  • No communication with others (electronic, verbal, written or otherwise) is allowed during the exam. Violations will result in a mark of zero and disciplinary action.

  • Add the Python code described below in the cells provided.

  • Test your code using the menu item Cell ► Run All

  • The message "Solution to question N may be correct." at the bottom of the notebook means that your answer to question N may be correct.

  • When the exam time is over, save the notebook (the .ipynb file) and upload it to the appropriate dropbox on the course web site.

Question 1

Create a list y with 20 elements where the value of the i'th element is equal to 20*i + 3. The values of i should range from 0 to 19.

In [ ]:
 

Question 2

The following code sets the variable s to a set of numbers. Create a set t consisting of all elements of s that are between 100 and 200 (inclusive).

In [ ]:
import random
s={n for n in [random.randrange(300) for i in range(30)]}

Question 3

Write a function called minvowel(s) that takes one string argument(s) and returns the smallest vowel in the string.
The ''smallness'' of a character should be determined by Python's comparison operators. Hint: use in.

In [ ]:
 

Question 4

Import the numpy package using the alias np. Write a function matpow(m,n) that returns the results of multiplying a numpy array m by itself n times. Do not use the ** operator.

In [ ]:
 
In [ ]:
# exam validation code; do not modify
def examcheck():
    import random, numpy as np
    
    try:
        if [(i-3)//20 for i in y] == list(range(20)):
            print("Solution to question 1 may be correct.")  
    except:
        pass
        
    try:
        if t == (s - {i for i in s if i<100} - {i for i in s if i>200}):
            print("Solution to question 2 may be correct.")
    except:
        pass
        
    try:
        if minvowel("biefg") == 'e':
            print("Solution to question 3 may be correct.")
    except:
        pass
        
    try:
        if (matpow(2*np.eye(3),3) == 16*np.eye(3)).all():
            print("Solution to question 4 may be correct.")
    except:
        pass
   

examcheck()