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)

Similar documents
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 Fall 2012 Final

CS 100 Spring 2016 Midterm 1

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

CS100 Spring 2017 Final

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

Control Flow: Loop Statements

Computer and Programming: Lab 1

a b c d e. none of the above

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

Lambda Notes for CS 2102

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

Python 1: Intro! Max Dougherty Andrew Schmitt

Lecture 15. For-Loops

CS 100 Fall 2013 Practice Midterm 2 / HW 11

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

15-110: Principles of Computing Sample Exam #1

SCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017

Python Intro GIS Week 1. Jake K. Carr

UNIVERSITY OF TORONTO SCARBOROUGH. Fall 2015 EXAMINATIONS. CSC A20H Duration 3 hours. No Aids Allowed

roboturtle Documentation

Fall 2018 Discussion 8: October 24, 2018 Solutions. 1 Introduction. 2 Primitives

Properties of Triangles

CPSC 217 Midterm (Python 3 version)

RECURSION: n. SEE RECURSION 3

Week 6: Introduction to Programming for GIS and Spatial Data Analysis GEO GEO A

CS 105 Lab As a review of what we did last week a. What are two ways in which the Python shell is useful to us?

Boardworks Ltd KS3 Mathematics. S1 Lines and Angles

CS100 Spring 2012 Midterm 1 Practice

CS 1301 Exam 1 Fall 2010

Fundamentals of Programming (Python) Getting Started with Programming

DM536 Introduction to Programming. Peter Schneider-Kamp.

CS 61A Interpreters, Tail Calls, Macros, Streams, Iterators. Spring 2019 Guerrilla Section 5: April 20, Interpreters.

SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015

CS 1803 Spring 2011 February 14, 2011 Exam 1 Name: Section: Grading TA:

CSCI 101 Midterm Sample Questions

CS61A Notes Week 13: Interpreters

61A Lecture 3. Friday, September 5

SCHEME INTERPRETER GUIDE 4

Spring 2018 Discussion 7: March 21, Introduction. 2 Primitives

Python for Non-programmers

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

Structure and Interpretation of Computer Programs

Project 2 Interpreter for Snail. 2 The Snail Programming Language

Test 1: Compsci 101. Kristin Stephens-Martinez. September 27, Honor code acknowledgment (signature)

UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFR08013 INFORMATICS 1 - FUNCTIONAL PROGRAMMING

Flow Control: Branches and loops

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

Lessons on Python Functions

Haskell Scripts. Yan Huang

There are three questions on this exam. You have 2 hours to complete it. Please indent your program so that it is easy for the grader to read.

CS 115 Lecture 8. Selection: the if statement. Neil Moore

9.2 Linux Essentials Exam Objectives

TAIL RECURSION, SCOPE, AND PROJECT 4 11

Write code that simulates one roll of a 6-sided die and prints out the

Reviewing all Topics this term

PIC 10A. Review for Midterm I

More Coding Basics with Some Turtle

Advanced Python. Executive Summary, Session 1

Structure and Interpretation of Computer Programs

PYTHON FOR KIDS A Pl ayfu l I ntrodu ctio n to Prog r am m i ng J a s o n R. B r i g g s

RECURSION, RECURSION, (TREE) RECURSION! 2

Strings and Testing string methods, formatting testing approaches CS GMU

Conditional Control Structures. Dr.T.Logeswari

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

Ch.5. Loops. (a.k.a. repetition or iteration)

CISC 1600 Lecture 3.1 Introduction to Processing

CS1110 Lab 6 (Mar 17-18, 2015)

Control Structures 1 / 17

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

Conditionals: Making Choices

Practice problems Set 2

CONTROL AND ENVIRONMENTS 1

CS 100: Gates and Drawing and Turtles

TUPLES AND RECURSIVE LISTS 5

CS 1110 Prelim 1 October 15th, 2015

Programming Language. Control Structures: Selection (switch) Eng. Anis Nazer First Semester

Comp 151. Control structures.

Getting Started with Python

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ June Exam

Expressions and Variables

Sketchpad Graphics Language Reference Manual. Zhongyu Wang, zw2259 Yichen Liu, yl2904 Yan Peng, yp2321

Understanding the Screen

CS 11 python track: lecture 3. n Today: Useful coding idioms

Homework 4 Questions

Getting Started. Office Hours. CSE 231, Rich Enbody. After class By appointment send an . Michigan State University CSE 231, Fall 2013

Introduction to Programming with Python Session 5 Notes

10/9/2012. Computers are machines that process data. assignment in C# Primitive Data Types. Creating and Running Your First C# Program

egrapher Language Reference Manual

C ONTROL AND H IGHER O RDER F UNCTIONS

Lecture 13. For-Loops

UNIX shell scripting

PDS Lab Section 16 Autumn Tutorial 3. C Programming Constructs

Programming in Python 3

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

UNIVERSITY OF TORONTO SCARBOROUGH. Wnter 2016 EXAMINATIONS. CSC A20H Duration 2 hours 45 mins. No Aids Allowed

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

ENVIRONMENT DIAGRAMS AND RECURSION 2

DEBUGGING TIPS. 1 Introduction COMPUTER SCIENCE 61A

DaMPL. Language Reference Manual. Henrique Grando

Transcription:

Multiple choice questions 1-10 (4 points each) Question 1 boolsseen = 0 bools = [not True, not False, True, False, True and False, True or False] for expr in bools: if expr: boolsseen += 1 print(boolsseen) # Hint: x += 1 is the same as x = x+1 a. SyntaxError: invalid syntax b. 1 c. 2 d. 3 Question 2 aseq = [2, 1, 0, -1, -2] sum = aseq[0] + aseq[-1] + aseq[-2] print(sum) a. -1 b. 0 c. 1 d. 2 Question 3 mix = ['zero', 0, ['two'], -1] print(mix[0:-1]) a. [0, ['two']] b. [0, ['two'], -1] c. ['zero', 0, ['two']] d. ['zero', 0, ['two'], -1] Question 4 alist = ['one', -1, 2] prefix = alist[:2] suffix = alist[-1:] print(prefix + suffix) a. ['one', -1, 2, -1, 2] b. ['one', -1, -1, 2] c. 1 d. [2, -1]

Question 5 import turtle s = turtle.screen() t = turtle.turtle() for i in range(4): if i%2 == 0: t.right(60) t.forward(100) t.right(60) a. a straight line b. two sides of a square c. two sides of an equilateral triangle d. an equilateral triangle Question 6 def check(alist): for element in range(len(alist)): if str(alist[element]) == alist[element+1]: return True return False arg = [0, '0', 1, '1'] matched = check(arg) print(matched) a. True b. False c. True True d. True False True

Question 7 muchsnow = False verycold = True taketrain = True if muchsnow: print("school closed") else: print("give exam") if verycold: print("car won't start") elif taketrain: print("take exam") else: print("miss exam") a. give exam b. give exam car won't start take train c. give exam car won't start miss exam d. SyntaxError: multiple 'if' Question 8 isaac = ['I','do','not','fear','computers','I','fear','the','lack','of','them'] short = 3 shortcount = 0 for word in isaac: if len(word) <= short: shortcount += 1 print(shortcount) a. 0 b. 2 c) 4 d) 6 e) none of the above

Question 9 def notin(letter, wordlist): rtnlist = [] for word in wordlist: if letter not in word: rtnlist.append(word) return rtnlist quote = ['round', 'up', 'the', 'usual', 'suspects'] print(notin('e', quote)) a. ['round'] b. ['round', 'up', 'usual'] c. [] d. TypeError: argument of type 'int' is not iterable Question 10 def accumulate(sequence): returnval = [] for element in sequence: returnval.append(element) return returnval print(accumulate('anagram')) a) ['anagram'] b) ['angrm'] c) 'anagram' d) ['a','n','a','g','r','a','m'] e) none of the above

Programming questions 11-13 (20 points each) Question 11 Part A: 10 points A tick is a short line that is used to mark off units of distance along a line. Write a function named drawtick() that uses a turtle parameter to draw a single tick of specified length perpendicular to the initial orientation of the turtle. The function drawtick() takes two parameters: 1. a turtle, t, that is used to draw 2. an integer, ticklen, that is the length of the tick When drawtick() is called, t is in the location that the first tick should be drawn. (Hint: remember that the tick mark should be drawn perpendicular to the orientation that t is in when it is called.) You should not make any assumptions about the initial up/down state of t. On return from drawticks(), t should be in the same location and have the same orientation that it had when it was called. Part B: 10 points Write a function named drawticks() that calls drawtick() repeatedly to draw a set of parallel tick marks. The function drawticks() takes four parameters: 1. a turtle, t, that is used to draw 2. an integer, ticklen, that is the length of the tick 3. an integer, numticks, that is the number of ticks to draw 4. an integer, distance, that is the distance between parallel tick marks For example, the following would be correct output if drawticks() were called by this code: import turtle s = turtle.screen() turt = turtle.turtle() drawticks(turt, 5, 10, 15)

Question 12 (20 points) Write a function named beginswith() that computes how many strings in a list of strings begin with a specified letter. The function beginswith() takes two parameters: 1. letter, a string of length 1 2. strlist, a list of 0 or more strings The function beginswith() should return an integer that is the number of strings in strlist that begin with letter. You may assume that no word in strlist begins with a capital letter. The following is an example of correct input and output for the function beginswith(): >>> eliza = ['the','rain','in','spain','falls','mainly','on','the','plain'] >>> firstletter = 't' >>> print(beginswith(firstletter, eliza)) 2 Question 13 Write a function named greeting(). The function greeting() should ask the user for their name, and then ask the user for the day of the week. It should then greet the person by name and day and comment whether their name has fewer, more than or the same number of characters as the day. The function greeting() takes one parameter: a string named greetstr. The following is an example of correct input and output for the function greeting(): >>> greeting('happy') What's your name? Justin What day is today? Monday Happy Monday Justin Your name has the same number of characters as today!