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

  1. Valid Variable Names in Python (Circle valid names):

    • Options: Int, lab, 12, 10cents, avg_value

  2. Expression Values (Given Values):

    • Assignments:

      • e = 3

      • h = 2.8

      • f = 14

      • g = 20

      • m = [1, 2, 3, 4, 5, 6]

    • Evaluation and errors on expressions:

      • a) h + f // g: yields a value

      • b) g + f)/int(h) + m[2]: yields a value

      • c) g - -18**(e * m[1])**(g // m[5]) - f): yields a value

      • d) Length of j: raises an error

      • e) m + 7 - 6/2 + 3: yields a value

  3. True/False Conditions:

    • Evaluate logical conditions for truth value.


Page 3

  1. Loop Iterations:

    • Analyze iterations of for loops using range:

    • a) for x in range(27, 8, -3): 9 iterations

    • b) for k in range(4, 13): 9 iterations

  2. 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]}
  1. Identifying Immutable Types:

    • Lists

    • Strings

    • Tuples

    • Dictionaries

    • Range objects


Page 4

  1. 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 removal

    • d) String replacement examples

    • e) Determine output after insert function


Page 5

  1. 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

  2. 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

  1. 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

  1. Password Validation Function:

  • Validate password standards (length, character types).

  • Replacements and formats to ensure pass validity.

  • Output final validated password.


Page 8

  1. Corrections to Temperature Table Code:

  • Fixed logic and syntax for temperature conversion calculations.

  • Ensure proper function calls and output printing.