Compsci 101 Fall 2015 Exam 1 Rubric. Problem 1 (24 points)

Similar documents
Compsci 101: Test 1.2

CompSci 101, Fall 2015, Rubric for Exam 2. Problem 1

Part A. What is the output of the following code segments? Write the output to the right. Note that there is only output for the print statements.

CS 115 Exam 3, Spring 2014

CS 1110 Final Exam Solutions May 2018

cs1114 REVIEW of details test closed laptop period

Real Python: Python 3 Cheat Sheet

CS 1301 Exam 1 Fall 2010

CMSC 201 Fall 2016 Lab 09 Advanced Debugging

MITOCW watch?v=0jljzrnhwoi

CS 1301 Exam 1 Fall 2010

Review Sheet for Midterm #1 COMPSCI 119 Professor William T. Verts

Part A. What is the output of the following code segments? Write the output to the right. Note that there is only output for the print statements.

Slicing. Open pizza_slicer.py

The Three Rules. Program. What is a Computer Program? 5/30/2018. Interpreted. Your First Program QuickStart 1. Chapter 1

Python for Non-programmers

University of Maryland College Park Dept of Computer Science CMSC106 Fall 2016 Midterm I

CS 303E Fall 2011 Exam 2 Solutions and Criteria November 2, Good Luck!

Intro. Scheme Basics. scm> 5 5. scm>

ECS Baruch Lab 3 Spring 2019 Name

Definition: A data structure is a way of organizing data in a computer so that it can be used efficiently.

A lot of people make repeated mistakes of not calling their functions and getting errors. Make sure you're calling your functions.

PREPARING FOR PRELIM 1

Consider the following variables and their values for the table below.

The Big Python Guide

Remember, this question was mis-worded: you could also add quoted words and sentences in the blanks below. This allowed for a solution to [4] below.

CSCE 110: Programming I

Intro. Comparisons. > x > y if and only if x is bigger than y. < x < y if and only if x is smaller than y.

CS 111X - Fall Test 1 - KEY KEY KEY KEY KEY KEY KEY

Introduction to: Computers & Programming: Review prior to 1 st Midterm

CS 1301 Exam 1 Answers Fall 2009

Lists, loops and decisions

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 10: OCT. 6TH INSTRUCTOR: JIAYIN WANG

We've tried to include the common errors and grading standard for every question.

5. PLEASE TAKE HOME the question bundle, but turn in 2 paper sheets: The scantron AND the paper where you wrote your programming question solution!

CSC148, Lab #4. General rules. Overview. Tracing recursion. Greatest Common Denominator GCD

Exam 1 Format, Concepts, What you should be able to do, and Sample Problems

Variables, expressions and statements

7. (2 pts) str( str( b ) ) str '4' will not compile (single, double, or triple quotes

Midterm #2 With Solutions solutions in blue marking notes in red

MITOCW watch?v=hverxup4cfg

Please write your answers clearly and neatly we can t give you credit if we can t decipher what you ve written.

Computer Science Foundation Exam

MITOCW watch?v=rvrkt-jxvko

Question 1. Part (a) Simple Syntax [1 mark] Circle add_ints(), because it is missing arguments to the function call. Part (b) Simple Syntax [1 mark]

CS 1301 Exam 2 Fall 2010

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

First name (printed): a. DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

The following content is provided under a Creative Commons license. Your support

Math 1MP3, midterm test February 2017

Chapter 4 Lab. Loops and Files. Objectives. Introduction

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define

CS102: Standard I/O. %<flag(s)><width><precision><size>conversion-code

Summer Final Exam Review Session August 5, 2009

Gold Hw8 Problem 3: TT Securities, Incorporated

CS 142 Style Guide Grading and Details

EXAMINATION INSTRUCTIONS

How to Design Programs

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points)

The type of all data used in a C (or C++) program must be specified

Slide 1 CS 170 Java Programming 1 The Switch Duration: 00:00:46 Advance mode: Auto

Fall 2017 Discussion 7: October 25, 2017 Solutions. 1 Introduction. 2 Primitives

CS 102 Lab 3 Fall 2012

Text Input and Conditionals

CS16 Exam #1 7/17/ Minutes 100 Points total

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Lab 10: OCaml sequences, comparators, stable sorting 12:00 PM, Nov 12, 2017

Abstract Data Types. CS 234, Fall Types, Data Types Abstraction Abstract Data Types Preconditions, Postconditions ADT Examples

EXAMINATION INSTRUCTIONS

MITOCW watch?v=kz7jjltq9r4

Loop structures and booleans

Computer Science Foundation Exam

Comp Exam 1 Overview.

Lab 1: Input, Processing, and Output This lab accompanies Chapter 2 of Starting Out with Programming Logic & Design.

3 The L oop Control Structure

CS 11 Haskell track: lecture 1

CS 111X - Spring Final Exam - KEY

Introduction to Computer Programming for Non-Majors

Most of the class will focus on if/else statements and the logical statements ("conditionals") that are used to build them. Then I'll go over a few

Midterm #1 Fall minutes

CS3 Midterm 1 Fall 2006

Python allows variables to hold string values, just like any other type (Boolean, int, float). So, the following assignment statements are valid:

Exceptions CS GMU

CS 106 Introduction to Computer Science I

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

Exception Handling. Genome 559

PHP Personal Home Page PHP: Hypertext Preprocessor (Lecture 35-37)

Supporting Class / C++ Lecture Notes

Your Name: Your TA's Name: 1 / 10 CS 1301 CS1 with Robots Fall 2008 Exam 3

Comp 150 Exam 2 Overview.


Account joeacct = new Account (100, new Account (500)); Account joeacct = new Account (100, new Account (500, null));

Sets. Sets. Examples. 5 2 {2, 3, 5} 2, 3 2 {2, 3, 5} 1 /2 {2, 3, 5}

The type of all data used in a C++ program must be specified

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

A Brief Introduction to Python

CPTS 111, Fall 2011, Sections 6&7 Exam 3 Review

Introduction to Python

MITOCW watch?v=9h6muyzjms0

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Transcription:

Compsci 101 Fall 2015 Exam 1 Rubric Problem 1 (24 points) Each answer is one point each. Spelling of int, integer doesn't matter. Similarly string, str doesn't matter. For the value column all answers must match exactly for one point EXCEPT, quotes don't matter for strings, e.g., orange and "orange" and 'orange' are the same. Notice the opportunity for one point "bonus" for the comma shown in ['two, ', 'three'], but cannot receive more than 24 pts total. This point was not given if this particular entry was wrong. fruits = ["apple", "pear", "orange", "banana", "blueberry"] s = "one, two, three o'clock, four o'clock rock" a = s[5] string 't' x = len(fruits) int 5 z = s.count(",") int 3 y = s.find("z") int 1 w = fruits[2] string 'orange' d = len(fruits) > len(s) boolean False e = s.split()[1:3] list ['two,', 'three'] g = 30/7 int 4 h = 27 % 12 int 3 q = 100 * 1.0 / 4 float 25.0 t = fruits[0][ 1] string e u = int("123") int 123 v = fruits[ 1] string 'blueberry'

Problem 2 (8 points) def volume(side, height): return (math.sqrt(3) /(12)) * side * side * height ALTERNATE SOLN: def volume(side, height): x = 1.73205 /12 return x * side * side * height Rubric: +1 point for using sqrt(3) or 1.73205 in numerator and 12 in denominator of an expression +2 points for multiplying side*side * height, note can be side**2 * height +1 point for a return statement with a float that has some expression with side or height +4 for return statement that uses side, height, and an expression with a numerator and denominator that is correct, either directly or with variables, but syntax errors ok, see below You cannot lose points for something you don't get credit for! 1 for a Python error that interferes with correctness, no errors if code doesn't interfere with correctness or no points awarded Example, 1 if used b and h instead of side and height

Problem 2 Part 2 (12 points) def zapfindex(word): if len(word) < 4: return 2 if word[ 1] == 's': if word[ 3:] == 'ies': return 10 else: return 7 if len(word) > 10 and word[ 1]!= 's': return 5 return 13 Alternate Solution: def zapfindex(word): if len(word) < 4: return 2 if word[ 3:] == 'ies': return 7 if word[ 1] == 's': return 7 if len(word) > 10: return 5 return 13 Note, code above is not the only way to be correct, for example there can be many uses of else in sequential if statements that are ok, and the else before return 7 isn't required, for example. The and word[ 1]!= 's' is not necessary above, for example +1 compares len(word) to 4 and returns 2 +1 compares len(word) to 10 and returns 5 +1 word ending in s checked correctly, e.g., [ 1] or [word.length() 1], in the context of returning 10 or 7, though correct return value doesn't matter, just trying +1 word ending in 'ies' done correctly, e.g., [ 3:] or.endswith("ies"), in context of returning 10 or 7 somehow, correctness of return value doesn't matter, just trying +2 fall through of return 13 is clear in code, this is an attempt point, actual logic could mean it doesn't work, but attempt is clearly visible

+2 does 's' and 'ies' correctly for all words except for less than 4 or greater than 10 +4 function is totally correct for all paths and words, will require careful tracing Example, 4 if don t use return accept at end and thus only return 13 or 7 every time. Example, 1 if no return at all

Problem 3 (8 points) def average(numbers): total = 0 count = 0 for n in numbers: total += n count += 1 return total*1.0/count General idea is that there are two counters, loop over numbers, accumulate values +2 see loop over the list numbers, with some expressions using either total or count (doesn't have to be both. The list syntax can be wrong, but clearly a loop over values of list with expression in the loop body. These are "right idea" points +2 loop syntax correct and includes a variable after for that's referenced in loop body +4 code is totally correct, except for syntax errors that the compiler would catch 1 Python error that earned points in rubric above, 1 another "real" syntax issue, can lose 2 points if 2 or more earned, can't go negative with respect to points earned. Example, 1 if no return Example, 2 if use len as part of range range(len(numbers))

Problem 4 Part A (8 points) def novowels(word): answer = "" for ch in word: if isvowel(ch): answer = answer + "*" else: answer = answer + ch return answer Note, it's ok to write isvowel(ch) == True, and it's ok to use += for concatenation. +2 points for initializing a string to the empty string, using it inside a loop over words. Must have initialization and use in loop body OR for using string inside loop and returning it must have use in loop and either init or return +1 for returning a string that's used in the loop body OR for initialization (see above), must have earned the +2 above for this. If they're just missing init or missing return they lose this, but get the +2 above. +1 for calling isvowel with variable used in for loop, doesn't matter if return value not used, or if syntax messed up, this is an idea point for calling isvowel +1 points for adding '*' correctly to string in the context of calling isvowel OR for adding ch if isvowel is false. Doing one or other other gets +2 +3 code is correct, except perhaps for syntax errors that are minor 1 Python syntax issue/usage error that earned points. No deductions for code that didn't earn points 1 can be repeated if needed, but only up to 2 and only if code earned points

Problem 4 Part b (8 points) def newlist(words): answer = [] for word in words: if isvowel(word[0]) answer.append(novowels(word)) else: answer.append(word) return answer ALTERNATE SOLUTION: def newlist(words): answer = [] for word in words: modified = word if isvowel(word[0]) modified = novowels(word) answer.append(modified) return answer +1 for creating a list that's empty and using it inside the loop OR for using a list in the loop body and returning it must be clearly a list +1 returning or initializing when the other +1 point were earned +1 for calling novowels with variable used in for loop and using the value returned by novowels +1 for calling isvowel and checking first character of variable used in loop, attempt is clear +2 adding variable used in loop to a list in the context of getting at least one of the previous two points or having no else +2 code is totally correct, except for syntax/usage error 1 Syntax/usage error, but must have earned a point

Problem 5 Part 1 (8 points) def totalbill(adjective, fare): return fare + tipamount(adjective)/100 * fare +2 call tipamount with adjective as a parameter and store/use the result in any expression that seems related to tips (using tipamount and adjective points) +2 add fare to some expression that seems related to tips (using fare points) +1 realizes should divide by 100, tries that related to value returned by tipamount +3 expression is correct except for small errors, e.g., float etc 1 syntax error/python error, but only in context of earning points

Problem 5 Part 2 (8 points) A why is the if statement there? +1 If statement discussed with words that indicate "to see if value in list", "adjective in words", supply default value +1 if states that calling.index results in an error when value not in list (expect this to be very rare point) B use/purpose of.index +1 find index or location of adjective in list words +1 use this value to do something with other list must mention other use, not just what.index does, but doesn't have to be completely on target C both lists used together +1 hints that locations in one list of adjectives correspond to tip amounts in other lists, uses words that are kind of on track +1 crisp explanation that words[i] and percentages[i] are closely related D adding new value +1 explain that values will be added to lists, anything close to this gets this "try" point +1 clear in where values added, front, back, middle is ok, but clearly added in same location Cannot earn points for D except for modifying lists

Problem 6 Part A (8 points) def category(filename, category): answer = [ ] f = open(filename) for st in f: data = st.strip().split(",") foodtype = data[0] if foodtype == category: answer.append(data[1]) return answer +2 uses file correctly, but broken down as ( can earn 1 or 2 here ) +1 opens the file using filename parameter and does something with a loop involving files +1 clear in code that loop over the file processes line at a time +2 uses data[0] (or equivalent with other variable name than data) and compares it to parameter category ( can only earn 2 or 0 here ) To earn this point must see index of something related to line at a time and must see if statement with = or == and category +2 uses data[1] and does something with it related to adding to list, must be clear that value in "middle" of line is added to list for this point ( can only earn 0 or 2 here ) +2 everything correct This is where points for initializing list missing, or not returning list missing. This is an all or nothing correctness, we've already given points for knowing how to initialize lists and use them properly DOES NOT matter if f.close() is called, unless it's called inside the loop, that is a 1 Python error

Problem 6 Part B (8 points) def biggest(filename): largest = 0 answer = "" f = open(filename) for st in f: data = st.strip().split(",") num = float(data[2]) if num > largest: largest = num answer = data[1] return answer ALTERNATE SOLUTION: def biggest(filename): largest = [] names =[] f = open(filename) for st in f: data = st.strip().split(",") num = float(data[2]) largest.append(num) names.append(names[0]); bignum = max(largest); pos = largest.index(bignum) return names[pos] +4 logic for finding largest is evident, broken down as follows +1 for initializing a value and comparing it with if inside the loop and resetting it, this can be string or calories. This is an idea/logic point, not a syntax point +1 for correctly tracking max calories, that means use > appropriately with value of loop and reset it. This is an idea/logic point, not a syntax point +2 for keeping track of both calories and the food that had the calories, this means must update in loop inside the if statement and return the value it's ok to be wrong with float and data[2] here, this is max logic +2 accesses data[2] and tries to convert to float (must be part of line) +1 tries to convert to float, or realizes it's a string and does something with it

+1 correctly uses float(val) to convert this is independent of logic with if and max, just converting a value from the list of values to a float +2 everything correct, minor Python syntax errors don't matter, this is +2 for correct after other points 1 for Python errors that are minor, mostly for final +2 points, conceivably if needed in other point earning categories. Note: You have to convert to a number, the string 123 is greater than the string 86, the number can be float or int.