CS 100 Spring 2016 Midterm 1

Similar documents
CS100 Spring 2017 Final

CS 100 Fall 2012 Final

a. SyntaxError: invalid syntax b. 1 c. 2 d. 3 e. none of the above Question 2 aseq = [2, 1, 0, -1, -2] sum = aseq[0] + aseq[-1] + aseq[-2] print(sum)

CS 111X - Fall Test 1

a b c d e. none of the above

a. -1 b. '-1' c. Index Error: list index out of range d. TypeError: unsupported operand type(s) for +: 'int' and 'str' e.

CS 100 Spring 2014 Roadmap to Computing Final May 14, 2014

CSE 131 Introduction to Computer Science Fall 2016 Exam I. Print clearly the following information:

Final Exam Version A

Structure and Interpretation of Computer Programs Spring 2017 Mock Midterm 1

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

CS 111X - Spring Final Exam - KEY

EXAMINATION INSTRUCTIONS

In addition to the correct answer, you MUST show all your work in order to receive full credit.

Introduction to: Computers & Programming: Review prior to 2 nd Midterm

Multiple choice questions 1-10 are worth 4 points each Question 1 x = 2 for i in range(3): print(x, end = ' ') x += i

IMPORTANT: Circle the last two letters of your class account:

Part 1 (80 points) Multiple Choice Questions (20 questions * 4 points per question = 80 points)

Question 1 for i in range(-3, 0): print(i, end=' ') a. no output b c d e. none of the above

CS 115 Exam 1, Fall 2015 Thu. 09/24/2015

Spring 2017 CS 1110/1111 Exam 1

CS150 - Sample Final

Control Flow: Loop Statements

CSE 131 Introduction to Computer Science Fall Exam I

CSE 131 Introduction to Computer Science Fall Exam I

CS164: Midterm I. Fall 2003

CS112 Spring 2012 Dr. Kinga Dobolyi. Exam 2. Do not open this exam until you are told. Read these instructions:

CS 1301 Exam 1 Fall 2010

Spring 2017 CS 1110/1111 Exam 2

Answer Key: CIS 166 Final Exam, Version 3, Spring 2015

Draw beautiful and intricate patterns with Python Turtle, while learning how to code with Python.

Spring 2017 CS 1110/1111 Exam 3

CS 1301 Exam 1 Fall 2010

CS150 Sample Final. Name: Section: A / B

Structure and Interpretation of Computer Programs Fall 2015 Midterm 1

Computer and Programming: Lab 1

Question 2. [2 points] Which of the following is a correct statement to obtain user input? (Assume that fleems is an int variable.

CS 115 Exam 3, Spring 2014

CS 455 Midterm Exam 1 Fall 2015 [Bono] Thursday, Oct. 1, 2015

CIS 110 Introduction to Computer Programming. 13 February 2013 Make-Up Midterm Midterm

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

CS 1301 Exam 2 Fall 2010

CS 415 Midterm Exam Spring 2002

Final Examination CSE 100 UCSD (Practice)

Midterm I - Solution CS164, Spring 2014

Spring Semester 09 Exam #1 Dr. Dillon. (02/19)

Version B Final Exam

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

Structure and Interpretation of Computer Programs

roboturtle Documentation

CSE 131 Introduction to Computer Science Fall Exam I

Structure and Interpretation of Computer Programs

Computer Science Grade 10 Sample -Term 2 Date: February 2018 Time: TBC Duration: 45 minutes

Spring Semester 11 Exam #1 Dr. Dillon. (02/15)

CS 1301 Exam 1 Fall 2014

CS 559 Computer Graphics Midterm Exam March 22, :30-3:45 pm

Q1: Multiple choice / 20 Q2: C input/output; operators / 40 Q3: Conditional statements / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

Reviewing all Topics this term

University of California, Berkeley. CS 186 Introduction to Databases, Spring 2014, Prof. Dan Olteanu MIDTERM

CPSC 121: Models of Computation Assignment #5

Lecture 10: Boolean Expressions

Structure and Interpretation of Computer Programs

York University AS/AK/ITEC INTRODUCTION TO DATA STRUCTURES. Midterm Sample I. Examiner: S. Chen Duration: One Hour and 30 Minutes

CS150 Sample Final Solution

CS 2316 Exam 1 Spring 2013

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

Sample Final Exam Questions

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

EXAMINATION INSTRUCTIONS

Q1: Multiple choice / 20 Q2: C input/output; operators / 40 Q3: Conditional statements / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

CS Name : Grading TA:

First Midterm Exam CS164, Fall 2007 Oct 2, 2007

CS Boolean Statements and Decision Structures. Week 6

Structure and Interpretation of Computer Programs Summer 2015 Midterm 1

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

CS 151 Midterm. (Last Name) (First Name)

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

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs Fall 2016 Midterm 2

Question 1. [5 points] Circle and briefly explain the error(s) in the following code:

CS 1063 Introduction to Computer Programming Midterm Exam 2 Section 1 Sample Exam

CSE 131 Introduction to Computer Science Fall Exam II

Structure and Interpretation of Computer Programs

CS 1301 Exam 1 Fall 2014

Midterm #2a Spring minutes DO NOT WRITE IN THIS AREA

(the bubble footer is automatically inserted in this space)

GWC Lesson 9 Partner Work and Comprehension

Midterm #1a Fall minutes

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.

Exam 2. Name: UVa ID:

CS100 Spring 2012 Midterm 1 Practice

Structure and Interpretation of Computer Programs

The American University in Cairo Computer Science & Engineering Department CSCE Dr. KHALIL Exam II Spring 2010

CS 1301 Exam 1 Fall 2013

Structure and Interpretation of Computer Programs

MATH 1075 Final Exam

CS 1301 Exam 1 Fall 2013

University of Illinois at Chicago Department of Computer Science. Final Examination. CS 151 Mathematical Foundations of Computer Science Fall 2012

Answer Key: CMP 167 Final Exam, Version 4, Spring 2015

Transcription:

CS 100 Spring 2016 Midterm 1 Monday, Feb 15, 2016 There are 13 questions on this test. Record your answers to the first 10 questions by circling a letter below. Answer questions 11, 12 and 13 on the attached pages. We have also provided scratch pages for writing trial code for the programming problems and tracing code for the multiple choice problems. Work on the scratch pages will not be graded. The value of each question is 1-10 multiple choice (4 points each) 11-13 programming (20 points each) There is a penalty of one point if your name is not clearly legible and one point if your section is not correct. Allocate your time accordingly. You may receive partial credit for questions 11, 12 and 13. Answer them as completely as you can. If you finish early, use the extra time to double check your work. When you are done, hand in this answer sheet (including programming question solutions) and sign the exam attendance sheet. You may use the summary of Python language elements that is provided. You may not use other notes, books or electronic devices. If you have brought a cell phone or other mobile device you must leave it with the proctor during the exam. X Good luck! Name (print clearly) Student ID Section (see below) 02 TF 10:00 Vaks; 04 MR 2:30 Cohen; 06 MR 2:30 Diallo; 08 WF 10:00 Diallo; 10 MW 10:00 Spirollari; 12 TF 4:00 Vaks; 14 TF 2:30 Vaks; 16 MR 10:00 Diallo; 18 WF 1:00 Diallo; 102 W 6:00 Vaks Q1 a b c d e Q2 a b c d e Q3 a b c d e Q4 a b c d e Q5 a b c d e Q6 a b c d e Q7 a b c d e Q8 a b c d e Q9 a b c d e Q10 a b c d e

Write code for Question 11 here. Use vertical lines for indentation.

Write code for Question 12 here. Use vertical lines for indentation.

Write code for Question 13 here. Use vertical lines for indentation.

Question 1 snap_freeze = True blizzard = False if snap_freeze and blizzard: print('1') elif not snap_freeze or not blizzard: print('2') if snap_freeze or blizzard: print('3') else: print('4') a. 1 b. 2 c. 3 d. 4 Question 2 letters = ['p','y','t','h','o','n'] concat = letters[3] + letters[-2] + letters[2] print(concat) a. toy b. hot c. thy d. IndexError: negative index Question 3 somestrings = ['cs', '100', 'midterm'] print(somestrings[1:2]) a. 0 b. ['cs', '100'] c. ['100'] d. ['100', 'midterm'] Question 4 alist = [2, -1, -2] slicea = alist[:2] sliceb = alist[-1:] print(slicea + sliceb) a. [-1, -2] b. [2, -1, -2] c. [2, -2] d. [2, -1, -2, -2]

Question 5 import turtle s = turtle.screen() t = turtle.turtle() for i in range(5): if i//4 == 0: t.forward(100) t.right(90) # Hint: '//' is integer division a. two adjacent sides of a square b. three sides of a square c. a square d. ZeroDivisionError: division by zero Question 6 def lettercount(astr, aletter): if aletter in astr: return True elif astr.count(aletter) > 1: return 'many' return False result = lettercount("loop", 'o') print(result) a. True b. True many c. False d. SyntaxError: multiple return statements Question 7 electionyear = True leapyear = True if electionyear: print('lots of ads') if not leapyear: print('feb has 28') else: print('quadrennial') a. lots of ads b. lots of ads Feb has 28 c. lots of ads quadrennial d. SyntaxError: multiple 'if'

Question 8 caps = 'ABCDEFGHIJKLMNOPQRSTUVWYXY' vowels = 'aeiouaeiou' etiquette = 'do not SHOUT' mystr = '' for letter in etiquette: if letter in vowels or letter in caps: mystr += letter print(mystr) a. ooshout b. oooshout c. o o SHOUT d. oooshut Question 9 def comparesize(anobject, length): objectlen = len(anobject) if objectlen == length: return 'equal' if objectlen == 0: return '0' else: return 'not 0' return objectlen print(comparesize('week', 7)) a. equal b. not 0 c. not 0 4 d. SyntaxError: multiple return statements Question 10 def rangeexample(astring, stop, interval): returnval = '' myrange = range(1, stop, interval) for idx in myrange: returnval += astring[idx] return returnval print(rangeexample('do unto others', 13, 4)) a. Dno b. otts c. ooe d. IndexError: index out of range

Question 11A (10 points) Write a function named drawsquare. The function drawsquare takes two parameters: a turtle, t an integer, length, that is the length of a side of the square. The function drawsquare should use the parameter t to draw the square. Do not make any assumptions about the initial up/down state of the turtle, its position on the screen or its orientation. The function drawsquare should begin drawing with the turtle at its initial position and orientation. When drawsquare returns, the turtle should again be in its initial position and orientation. You must use a loop for repeated operations. Question 11B (10 points) Write a function named drawsquares that calls drawsquare to draw a specified number of squares. The function drawsquares takes four parameters: a turtle t an integer size an integer num, the number of equal signs to draw an integer angle, the clockwise rotation between successive squares (Hint: you do not need to import the turtle module or create a screen and turtle. That would have to have been done before drawsquares is called.) For example, the following would be correct output. import turtle s = turtle.screen() snapper = turtle.turtle() drawsquares(snapper, 100, 4, 20)

Question 12 (20 points) Write a function named bigcount that counts how many elements in a list of numbers are greater than a threshold value and returns that count. The function bigcount takes two parameters: numlist, a list of numbers threshold, in integer For example, the following would be correct output: >>> somenums = [-5, 6, 3, 0, 7] >>> print(bigcount(somenums, 2)) >>> 3 Question 13 (20 points) Write a function named getdate. The function getdate takes one parameter: message, a string In addition to the parameter message, the function getdate should prompt the user for two items of input: first the month, then the day. The function getdate should produce two kinds of output. It should print out the month, day and message, separated by spaces return a string consisting of the month and day, separated by a space For example, the following would be correct input and output: >>> today = getdate('is a great day!') What month is it? February What day is it? 15 February 15 is a great day! >>> print(today) February 15