output
General Exam Information
CSC 295 Test 1
Name: John Andre Fortich
Unity ID: jb fortic
Total Points: 100 (105 with extra credit)
Total Pages: 9 (including this cover sheet)
Instructions:
Use space provided for answers
Dark writing if using a pencil
Closed book and closed notes exam
ONE-SIDED handwritten 3 x 5 inch card of notes permitted
Must turn in notecard at the end
Calculator allowed, but cannot share
Work must be individual and uphold integrity
Exam Rules and Procedures
Read each question carefully to avoid missing points.
You may use this page as scratch paper, but no graded answers here.
Must affirm no unauthorized assistance used (signed pledge).
Question Breakdown
Page 2
Valid Variable Names in Python (Circle valid names):
Options: Int, lab, 12, 10cents, avg_value
Expression Values (Given Values):
Assignments:
e = 3h = 2.8f = 14g = 20m = [1, 2, 3, 4, 5, 6]
Evaluation and errors on expressions:
a)
h + f // g: yields a valueb)
g + f)/int(h) + m[2]: yields a valuec)
g - -18**(e * m[1])**(g // m[5]) - f): yields a valued) Length of
j: raises an errore)
m + 7 - 6/2 + 3: yields a value
True/False Conditions:
Evaluate logical conditions for truth value.
Page 3
Loop Iterations:
Analyze iterations of for loops using range:
a)
for x in range(27, 8, -3): 9 iterationsb)
for k in range(4, 13): 9 iterations
Python Code Writing:
a) Create a list of evens:
evens = [x for x in range(2, 2001, 2)]b) Create a tuple:
tictactoe = ('win', 'loss', 'tie') * 30 ```
c) Create a dictionary:
checkout = {1: [3, 89, 2.99], 2: [55, 44, 1.99]}
Identifying Immutable Types:
Lists
Strings
Tuples
Dictionaries
Range objects
Page 4
Output from Code:
a) From concatenation of lists and tuples: Choose correct output
b) Accessing list of lists: Identify correct accessed element
c)
g.remove(3): Length after removald) String replacement examples
e) Determine output after insert function
Page 5
Assessing Code Outputs:
a) Lambda function: trace its output
b) Error checking with logic statements
c) Formatting issues in print statements
d) Dictionary operations translate into print
Outputs for Given Code Blocks:
a) Finding substring in a string
b) List comprehensions based on another list
c) Indexing within lists and length outputs.
Page 6
Function Definitions Required:
load_pos function:
Handles file input, reads until sentinel value 0
Includes logic to append positive values to a list.
count_list function:
Takes positive values from list and counts occurrences, returning a new list.
Page 7
Password Validation Function:
Validate password standards (length, character types).
Replacements and formats to ensure pass validity.
Output final validated password.
Page 8
Corrections to Temperature Table Code:
Fixed logic and syntax for temperature conversion calculations.
Ensure proper function calls and output printing.