[solution]: 1 Final Exam (Summer II 2016) Note: All pages of the exam

More Details:

I need help with the document attached. The code used in the assignment is Python.

1

Final Exam (Summer II 2016)

Note: All pages of the exam (including blank pages) must be submitted. Include

full name on all pages of the exam. Students are allowed a one-page cheat sheet.

Full Name: ______________________

Date ___________

1. (for loop, accumulator pattern) Write a loop that will repeatedly request whole numbers

from the user. When the user enters 0, a report should be printed saying how many

numbers were entered and their sum. The final 0 should not be counted as one of the

numbers. (5pts)

2

2. (for loop, accumulator pattern) Write a function emphasize() that takes as an input a

string s and returns (not prints) a string with spaces inserted between adjacent letters.

For example, if the function is called with the string ?Very important? it should return 'V

e r y i m p o r t a n t'

(5pts)

3

3. (function, while loop and break statement) Write a program that contains a function

firstNeg() that takes a (possibly empty) sequence (list or tuple) of numbers as input,

finds the first occurrence of a negative number, and returns the index of that number. If

there is no negative number or the list is empty, the function should return -1. Store the

value returned by the function into a variable (searchResult) and print the value of the

variable.

Example: if firstNeg() is called as follows: firstNeg([2, 3, -1, 4, -2]) it returns 2. If

firstNeg() is called as follows: firstNeg(), it returns -1. If firstNeg is called as follows:

firstNeg([2, 3, 1, 4, 2]), it returns -1.

(10pts)

4

4. (Set) Two lists are defined as follow: lst1 = [3, 5, 1, 7, 9, 4] and lst2 = [4, 2, 3, 9, 10]

(15pts)

a. Write python expressions that convert lst1 and lst2 into sets (setA and setB) (2pts)

b. Write a function, intersect(), that takes two sets as arguments and returns the

intersect of the two sets as a list. (5pts)

5

c. If function, intersect(), is called with setA and setB as arguments, which values

will the returned list contain (2pts)

d. Write a python expression that determines the union of the setA and setB (2pts)

e. Write a python expression that adds 25 to setA (2pts)

f. Write a python expression that empties setB (2pts)

5. (Dictionary, while loop, two-way if condition) Write a program that stores students

information (user id, first and last name, email and score) in a dictionary. The program

will generate a 6-digit random number as the key (user id) for each student. The student

name, email and score will be assigned as value to the key. Before storing information

into the dictionary, the program must first verify the key does not exist in the dictionary.

If the key already exists, the program should print a message (?Key is already assigned.

Current value will be overwritten?), and overwrite the existing value. This program

should use an infinite loop to continue prompting the user for information. The program

will prompt the user for first and last name, email and test score. (10pts)

6

7

6. Write python expressions for the following (10pts)

a. Create an empty set, setC

b. Add two numeric values (10 and 20) to setC

c. Create an empty dictionary, names

d. Add key/value pair 1 and ?John? and key/value pair 2 and ?Joe? to names

7. Use set and list operations below (5pts)

Note: A set cannot contain duplicates

values = [23, 19, 18, 21, 18, 20, 21, 23, 22, 23, 23, 19, 20]

a. Convert values to a set, setD. Print the values in setD

b. Write a python expression that sums the values in setD

8. What does Unicode use to represent characters in memory (5pts)

9. (format function) Write python expressions (at most two expressions) that print the

binary, hex, and decimal values of the letter Z. . Use one expression to return the ASCII

value of Z and a second expression that prints the binary, hex, and decimal representation

of the ASCII value of Z (5pts)

8

10. (Character Encoding) Use python expressions to complete the following (5pts)

a. Display the character for ASCII value 95

b. Display the ASCII value for the letter B

11. Review the code below and answer the questions that follow (10pts):

Note: This function finds the factorial of x

def factExample(x):

if x &lt; 1:

return 1

else:

global aFact

aFact = factExample(x ? 1) * x

return aFact

aFact = 1

print(aFact)

x=5

print(x)

aFact1 = factExample(x)

print(aFact1)

print(aFact)

a.

b.

c.

d.

e.

f.

What is the scope of the function factExample()

What is the scope of the variable aFact

What is the scope of the variable x in the function

What is the scope of the variable x outside of the function

What is the value of the variable aFact before the function call

What is the value of the variable aFact after the function call

9

g. What is the value of the variable aFact1

h. What is the value of the variable x (defined outside of the function) after the

function call

i. What is the value of the variable x outside of the function

j. Which statement in the code above contains a function call

12. (try/except) Write a program that prompts for two nonnegative numbers (x and y) and

performs division operation on the values. The value of x represents the numerator and

the value of y represents the denominator. The program should use try/except to handle

ValueError and ZeroDivisionError exceptions for non-numeric values or if the

denominator is 0 (zero). (10pts)

13. A recursive function that terminates must always have two characteristics/properties.

What are they? (5pts)

10

Solution details:
STATUS
QUALITY
Approved

This question was answered on: Dec 18, 2020 Solution~00031148133980.zip (25.37 KB)

This attachment is locked

We have a ready expert answer for this paper which you can use for in-depth understanding, research editing or paraphrasing. You can buy it or order for a fresh, original and plagiarism-free copy (Deadline assured. Flexible pricing. TurnItIn Report provided) Pay using PayPal (No PayPal account Required) or your credit card . All your purchases are securely protected by .

STATUS

QUALITY

Approved

Dec 18, 2020

EXPERT

Tutor 