NOTE: All references to Python on this exam mean Python 3, so you should answer accordingly.

Similar documents
NOTE: All references to Python on this exam mean Python 3, so you should answer accordingly.

e01 EXAM: e01: Midterm Exam CS8 F18 Name: Umail 10/24/2018 e01 - Midterm Exam - Gauchospace Gradescope Piazza

CS8 Final Exam E03, 09M, Phill Conrad, UC Santa Barbara 09/10/2009

CS16 Midterm Exam 1 E01, 10S, Phill Conrad, UC Santa Barbara Wednesday, 04/21/2010, 1pm-1:50pm

CS16 Midterm Exam 2 E02, 09F, Phill Conrad, UC Santa Barbara Wednesday, 11/18/2009

E02, W16, Phill Conrad, UC Santa Barbara

CS16 Midterm Exam 2 E02, 10W, Phill Conrad, UC Santa Barbara Tuesday, 03/02/2010

CS56 Midterm Exam. E01, W16, Phill Conrad, UC Santa Barbara Wednesday, 02/10/2015

***PRACTICE EXAM 02 for*** CS16 Midterm Exam 2 E02, 09F, Phill Conrad, UC Santa Barbara Actual exam scheduled for: 11/18/2009

CS56 final (E03) W15, Phill Conrad, UC Santa Barbara Wednesday, 03/18/2015. Name: Umail umail.ucsb.edu. Circle one: 4pm 5pm 6pm

CS32 Final Exam. E03, F15, Phill Conrad, UC Santa Barbara

CS 1110, LAB 1: EXPRESSIONS AND ASSIGNMENTS First Name: Last Name: NetID:

Also: JUST write your name at the top of all sheets and turn in all sheets UNCONNECTED.

#101 Page: 1 Name: CS32 Midterm Exam. E01, W15, Phill Conrad, UC Santa Barbara

CS32 Midterm Exam E01, F15, Phill Conrad, UC Santa Barbara Wednesday, 10/28/2015, 11am 12:15pm

CS16 Final Exam E03, 10S, Phill Conrad, UC Santa Barbara Wednesday, 06/09/2010

PREPARING FOR PRELIM 1

Overview of List Syntax

CS 2316 Exam 1 Spring 2014

CS 1110, LAB 1: PYTHON EXPRESSIONS.

Lecture 1. Types, Expressions, & Variables

CS 111X - Fall Test 1

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

Overloading Functions & Command Line Use in C++ CS 16: Solving Problems with Computers I Lecture #6

CS 1301 Exam 1 Fall 2010

Al Imam Mohammad Ibn Saud Islamic University College of Computer and Information Sciences Computer Science Department

ICS 31 UC IRVINE. ############## YOUR UCINET #### K E Y #### ############## Second Midterm YOUR NAME YOUR STUDENT ID (8 DIGITS)

CS150 Sample Final. Name: Section: A / B

CS 1301 Exam 1 Fall 2010

W13:Homework:H08. CS40 Foundations of Computer Science W13. From 40wiki

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

Introduction to C++ General Rules, Conventions and Styles CS 16: Solving Problems with Computers I Lecture #2

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

Lecture 2: Variables & Assignments

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

CS 101 Fall 2006 Midterm 1 Name: ID:

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

CSE 131 Introduction to Computer Science Fall Exam I

CSE 142 Sample Midterm Exam #3

Database Programming - Section 16. Instructor Guide

CS32 Final Exam. E03, S15, Phill Conrad, UC Santa Barbara Tuesday, 06/08/2015, 8am 11am

ECOR Come to the PASS workshop with your mock exam complete. During the workshop you can work with other students to review your work.

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

Strings in Python 1 Midterm#1 Exam Review CS 8: Introduction to Computer Science Lecture #6

CS 1803 Pair Homework 3 Calculator Pair Fun Due: Wednesday, September 15th, before 6 PM Out of 100 points

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

CS1114 Spring 2015 Test ONE ANSWER KEY. page 1 of 8 pages (counting the cover sheet)

Review for the Final Exam CS 8: Introduction to Computer Science, Winter 2018 Lecture #15

CS Final Exam Review Suggestions - Fall 2017

CS1110 Lab 1 (Jan 27-28, 2015)

CS 2316 Exam 4 Fall 2011

Variable and Data Type I

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Spring 03

The current topic: Python. Announcements. Python. Python

ENGR 102 Engineering Lab I - Computation

More Examples Using Functions and Command-Line Arguments in C++ CS 16: Solving Problems with Computers I Lecture #6

Question: Total Points: Score:

CS457/557 Functional Languages

Al Imam Mohammad Ibn Saud Islamic University College of Computer and Information Sciences Computer Science Department

W13:Homework:H07. CS40 Foundations of Computer Science W13. From 40wiki

CS 1301 Exam 1 Fall 2014

CS150 - Sample Final

CSCI 136 Data Structures & Advanced Programming. Fall 2018 Instructors Bill Lenhart & Bill Jannen

Variable and Data Type I

Lecture 1. Course Overview, Python Basics

Programming with Arrays Intro to Pointers CS 16: Solving Problems with Computers I Lecture #11

CS 455 Final Exam Fall 2015 [Bono] Dec. 15, 2015

CS 1110, LAB 12: SEQUENCE ALGORITHMS First Name: Last Name: NetID:

Advanced Algorithms and Computational Models (module A)

CIS 110 Introduction To Computer Programming. February 29, 2012 Midterm

Notes on Chapter 1 Variables and String

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

You may not share any information or materials with classmates during the exam and you may not use any electronic devices, including cellphones.

Lecture 1. Course Overview, Python Basics

CIS 110 Introduction to Computer Programming. February 29, 2012 Midterm

You may not share any information or materials with classmates during the exam and you may not use any electronic devices.

CS 455 Midterm Exam 1 Spring 2011 [Bono] Feb. 17, 2011

Structure and Interpretation of Computer Programs

CS 1301 Exam 1 Spring 2015

Introduction to Computer Programming CSCI-UA 2. Review Midterm Exam 1

CS 1301 Exam 1 Answers Fall 2009

Arrays 2 CS 16: Solving Problems with Computers I Lecture #12

CS150 Sample Final Solution

CSE 142 Sample Midterm Exam #3

UNIVERSITY OF CALIFORNIA

PYTHON MOCK TEST PYTHON MOCK TEST III

Lab # 02. Basic Elements of C++ _ Part1

CS 1301 Exam 1 Spring 2011

Course Overview, Python Basics

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

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

CSE 142, Summer 2013 Midterm Exam, Friday, July 26, 2013

Exam 2, Form A CSE 231 Spring 2014 (1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

Exam 2, Form B CSE 231 Spring 2014 (1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

CS Final Exam Review Suggestions - Spring 2014

CS 1301 Exam 1 Fall 2013

CS 1301 Exam 1 Fall 2013

CS 1301 Exam 1 Fall 2014

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

CSE 131 Introduction to Computer Science Fall Exam I

Transcription:

Name: (as it would appear on official course roster) Umail address: @umail.ucsb.edu EXAM: : Midterm Exam ready? date points true Tue 04/24 03:30PM 100 1 You may not collaborate on this exam with anyone. If you need to use the restroom, you must leave your cell phone with the exam proctor before leaving the room. Write your name at the top of this page AND EVERY ODD NUMBERED PAGE. Double check that you turned in ALL pages; look for "End of Exam" on the last page. This exam is closed book, closed notes, closed mouth, cell phone off. You are permitted one sheet of paper (max size 8.5x11") on which to write notes. This sheet will be collected with the exam, and might not be returned. Please write your name on your notes sheet. NOTE: All references to Python on this exam mean Python 3, so you should answer accordingly. 1. (10 pts) Many products in the United States that are sold by weight are measured in ounces, while in most other countries, they are measured in grams. One ounce is approximately 28.3495 grams, and the abbreviation for ounce is oz. Given this information, write the definition of a Python function called oz2g that takes a parameter called ounces and returns the corresponding value in grams. 2. (5 pts) Now write a function call to this function, as you might type it at the Python prompt, for example, that computes the number of grams equal to 3 ounces. https://ucsb-cs8-s18.github.io/exam//cs8_s18_/ 1/6

2 3. Testing a Python function can be done with the pytest module, as we did in lab02 and lab03 in this course. The handout you got with this exam has example code illustrating pytest test cases. a. (4 pts) Why do we need the pytest.approx thing? That is, why can t we just write: assert ctof(100.0)==212.0? b. (6 pts) Now consider the oz2g function you write earlier. Please write two test cases for that function appropriate for use with pytest. For convenience, here is a table of two values you may use: ounces grams 2.5 70.8738 3 85.0486 c. (5 pts) When using test cases, we often write a stub before writing the correct function definition. Write a function definition for oz2g that illustrates this practice that is, a function definition for oz2g with a stub. https://ucsb-cs8-s18.github.io/exam//cs8_s18_/ 2/6

Name: (as it would appear on official course roster) Umail address: 4. For the Python code in the left box, write the output in the right box @umail.ucsb.edu NOTE: The only difference between the two questions is that in one case, item has no quotation marks around it, while in the other case it does ("item"). That s on purpose. I want you to tell me what output Python will give in each of these two cases. If you are not sure, write your best guess. 3 (3 pts) the_list = ["CS","Math","PStat"] for item in the_list: print(item, end=" ") (3 pts) the_list = ["CS","Math","PStat"] for item in the_list: print("item", end=" ") https://ucsb-cs8-s18.github.io/exam//cs8_s18_/ 3/6

4 5. Assuming the following assignment statements have been entered at the Python prompt: school = "UC Santa Barbara" abbrev = "UCSB" course = "CS8" qtr = "M17" unis = ["UCSB","UCLA","Harvard","Yale","Stanford"] cols = ["red","green","blue"] cols.append("purple") cols.append("blue") Indicate the value of each of these expressions. IMPORTANT: Use strict Python syntax. If it s a string, put it in quotes. Boolean values should be indicated as False and True, no quotes, with the capital letter. Expression Result Expression Result (3 pts) 2 + 3 * 5 (3 pts) 10 % 3 (3 pts) abbrev * 2 (3 pts) len(qtr) (3 pts) qtr[0:2] (3 pts) unis[1]<unis[2] (3 pts) course[-1] (3 pts) len(unis) <= 8 (3 pts) len(cols) (3 pts) cols[-1][-1] (3 pts) cols[0] (3 pts) cols[2][0] (3 pts) len(cols[1]) (3 pts) "e" in cols[0] https://ucsb-cs8-s18.github.io/exam//cs8_s18_/ 4/6

Name: (as it would appear on official course roster) Umail address: @umail.ucsb.edu 6. (4 pts) A complete Python program that prints out the following message is a very short program indeed: I can code! 5 Please write that entire program in the space below. You certainly have more space than you will need. 7. (2 pts) To start work on a Python program you need to type a command that brings up the Integrated Development Environment for Python (version 3). What is this command? 8. (2 pts) What does the Unix mkdir command do? https://ucsb-cs8-s18.github.io/exam//cs8_s18_/ 5/6

6 9. Indicate with a check what Python will return as the type of each expression. Note that when Python reports a type, it reports it with expressions such as <class 'int'> and <class 'str'>. I m omitting the <class ' ' > part to save space. a. (2 pts) type("ucsb") str int float list tuple dict bool b. (2 pts) type(12) str int float list tuple dict bool c. (2 pts) type(1 + 2) str int float list tuple dict bool d. (2 pts) type("24") str int float list tuple dict bool e. (2 pts) type([3] + [4]) str int float list tuple dict bool f. (2 pts) type( 3 < 4) str int float list tuple dict bool g. (2 pts) type( {"green":"verde"} ) str int float list tuple dict bool End of Exam https://ucsb-cs8-s18.github.io/exam//cs8_s18_/ 6/6