CS100 Spring 2012 Midterm 1 Practice

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

CS1 Lecture 3 Jan. 18, 2019

61A Lecture 2. Friday, August 28, 2015

Python 1: Intro! Max Dougherty Andrew Schmitt

CS1 Lecture 3 Jan. 22, 2018

Programming for Engineers in Python. Autumn

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

Python Programming. Introduction Part II

CS 111X - Fall Test 1

Programming for Engineers in Python. Recitation 1

CMSC 201 Fall 2016 Lab 09 Advanced Debugging

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

CS 100 Fall 2013 Practice Midterm 2 / HW 11

CSCE 110: Programming I

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

Control Structures 1 / 17

Professor: Sana Odeh Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators

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

The current topic: Python. Announcements. Python. Python

CS177 Recitation. Functions, Booleans, Decision Structures, and Loop Structures

Comp Exam 1 Overview.

Lists, loops and decisions

Getting Started with Python

Scripting Languages. Python basics

Control Flow: Branching booleans and selection statements CS GMU

CMPT 120 Basics of Python. Summer 2012 Instructor: Hassan Khosravi

EXPRESSIONS, STATEMENTS, AND FUNCTIONS 1

1 Truth. 2 Conditional Statements. Expressions That Can Evaluate to Boolean Values. Williams College Lecture 4 Brent Heeringa, Bill Jannen

Spring Semester 10 Exam #1 Dr. Dillon. (02/18)

Chapter 5 Conditional and Iterative Statements. Statement are the instructions given to the computer to perform any kind of action.

Control and Environments Fall 2017 Discussion 1: August 30, Control. If statements. Boolean Operators

Introduction to Scientific Python, CME 193 Jan. 9, web.stanford.edu/~ermartin/teaching/cme193-winter15

PREPARING FOR PRELIM 1

Lecture 4. Defining Functions

C ONTROL AND H IGHER O RDER F UNCTIONS

Python for C programmers

Language Reference Manual

Fundamentals of Programming (Python) Getting Started with Programming

Beyond Blocks: Python Session #1

Logical Thinking through Computer Programming

Lecture 1. Types, Expressions, & Variables

Python The way of a program. Srinidhi H Asst Professor Dept of CSE, MSRIT

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

Control and Environments Fall 2017 Discussion 1: August 30, 2017 Solutions. 1 Control. If statements. Boolean Operators

Computer Science 217

CS 61A Control and Environments Spring 2018 Discussion 1: January 24, Control. If statements. Boolean Operators

CONTROL AND ENVIRONMENTS 1

CSE : Python Programming. Homework 5 and Projects. Announcements. Course project: Overview. Course Project: Grading criteria

06/11/2014. Subjects. CS Applied Robotics Lab Gerardo Carmona :: makeroboticsprojects.com June / ) Beginning with Python

CS 1301 Exam 2 Fall 2013

Computer Science is...

61A Lecture 3. Friday, September 5

Part III Appendices 165

S206E Lecture 19, 5/24/2016, Python an overview

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

Midterm 1 Review. Important control structures. Important things to review. Functions Loops Conditionals

Lecture 1. Course Overview, Python Basics

Chapter 3 : Informatics Practices. Class XI ( As per CBSE Board) Python Fundamentals. Visit : python.mykvs.in for regular updates

CSC 148 Lecture 3. Dynamic Typing, Scoping, and Namespaces. Recursion

Review. Input, Processing and Output. Review. Review. Designing a Program. Typical Software Development cycle. Bonita Sharif

Starting. Read: Chapter 1, Appendix B from textbook.

CSCI 101 Midterm Sample Questions

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

Midterm Exam 1 Solutions

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs

More Data Types. The Char Data Type. Variable Declaration. CS200: Computer Science I. Module 14 More Data Types

Python for Non-programmers

Programming in Python 3

Python BASICS. Introduction to Python programming, basic concepts: formatting, naming conventions, variables, etc.

DEBUGGING TIPS. 1 Introduction COMPUTER SCIENCE 61A

Teaching London Computing

Name Feb. 14, Closed Book/Closed Notes No electronic devices of any kind! 3. Do not look at anyone else s exam or let anyone else look at yours!

CS 1301 Exam 1 Fall 2014

Introduction to Python and Programming. 1. Python is Like a Calculator. You Type Expressions. Python Computes Their Values /2 2**3 3*4+5*6

CS 1301 Exam 1 Fall 2014

Real Python: Python 3 Cheat Sheet

CSE 142 Su01 Midterm 1 Sample Solution page 1 of 5

CS 115 Lecture 4. More Python; testing software. Neil Moore

Lecture 1. Course Overview, Python Basics

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

Flow Control. So Far: Writing simple statements that get executed one after another.

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

CS1110 Lab 1 (Jan 27-28, 2015)

All program statements you write should be syntactically correct. Partial credit is not guaranteed with incorrect use of syntax.

CS 1301 Exam 1 Spring 2014

Comp 150 Exam 2 Overview.

Python Activity 5: Boolean Expressions and Selection Statements

Large-Scale Networks

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

CMSC201 Computer Science I for Majors

Advanced Python. Executive Summary, Session 1

cs1114 REVIEW of details test closed laptop period

61A Lecture 2. Wednesday, September 4, 2013

CS100 Spring 2017 Final

SFPL Reference Manual

Basic Syntax - First Program 1

CSc 110, Spring Lecture 24: print revisited, tuples cont.

CSE 131 Introduction to Computer Science Fall Exam I

EXPRESSIONS, STATEMENTS, AND FUNCTIONS 1

Transcription:

CS100 Spring 2012 Midterm 1 Practice This practice midterm gives you a guide to the subject matter and format the first midterm of the semester. Assignment: Do the practice midterm and submit it via Moodle. Due: Friday, February 8, 2013 For questions 1-10, your answer to each question should be in three parts: i. The answer you get to the question without consulting the Python interpreter ii. The answer you get to the question after consulting the Python interpreter iii. A short (one or two sentence) explanation of any difference between i an ii. During the midterm you will not have access to the Python interpreter or your notes. You will be given a copy of a summary of elements of the Python language that you will find it useful to consult. While doing this practice midterm, you should: i) attend one or more office hour sessions with an instructor or classroom assistant and ii) pose questions about anything you don't understand on Moodle. Questions 1-10 are multiple choice (4 points each). Question 1. Which of the following is (are) true? 1 type(['word', 5]) == <class 'list'> 2 type(['word', 5, ['word', 5]]) == <class 'list'> 3 type([]) == <class 'list'> a. 1 only b. 1 and 2 only c. 1 and 3 only d. 1, 2 and 3 Question 2. What is the output of the following code? from turtle import * def line100(linecolor, width, painty): painty.color(linecolor) painty.width(width) painty.forward(100) exitonclick() t = Turtle() line100('blue', 5, t) a. a blue line of width 5 and length 100 b. Type error: string literal is not a valid parameter c. Import error: * is not an attribute of class Turtle d. NameError: global name 'Turtle' is not defined

Question 3. What is the output of the following code? weather = 'rain' if weather == 'rain': print('umbrella time') elif weather == 'cold': print('wear jacket') else: print('not cold') a. umbrella time b. umbrella time not cold c. the empty string d. Syntax error: elif Question 4. What is the output of the following code? thing = 1 index = 0 while index < 2: thing += thing index += 1 print(thing) a. 1 b. 1111 c. 4 d. Type error: unsupported operand type(s) Question 5. What is the output of the following code? bool0 = bool1 = False print(bool0 and bool1) print(bool0 or bool1) a. b. False c. False d. bool1bool2 bool0

Question 6. What is the output of the following code? def addthree(a, b, c): return a + b + c addthreeoutput = addthree(1, 2, 3) print(addthreeoutput) a. 123 b. 6 c. Parameter error: mismatched parameters d. Print error: unable to print int Question 7. What is the output of the following code? def paramtest(a, b): c = a + ' ' + b return c p0 = 'Durn' p1 = 'tootin' c = paramtest(p0, p1) print(c) a. ab b. a b c. Durntootin d. Durn tootin Question 8. What is the output of the following code? echooutput = echo("hello") print(findsaying) def echo(text): return text return text + text a. NameError: name 'echo' is not defined b. hello c. hello d. hello hellohello

Question 9. What is the output of the following code? num = 0 add = 2 while num < 5: num = num + add print(num) a. 0 b. 2 c. 4 d. 6 Question 10. What is the output of the following code? def paramtest(astr, anint): print(astr, 'is a str') print(anint, 'is an int') paramtest(1, 'one') a. 1 is an int one is a string b. one is an int 1 is a string c. TypeError: incompatible types d. ParameterError: integer type expected

Questions 11-13 are programming problems, worth 20 points each. Be sure to use proper indentation of your code. Question 11. Write a function named steps() that draws a staircase. Each step of the staircase consists of a vertical line and a horizontal line of the same length. The function steps() takes three parameters: 1. a turtle 2. an integer, stepsize, that is the height and depth of a step 3. an integer, numsteps, that is the number of steps to draw For example, if the function steps() is called by the following code, the drawing below would be correct output: from turtle import * turt = Turtle() steps(turt, 50, 3) Question 12. Write a function named inrange() that tests whether a given number falls within a specified range. The function inrange() takes three parameters: 1. testnum 2. floor 3. ceiling The function inrange() should return if testnum is greater than or equal to floor and less than or equal to ceiling. For example, the following would be correct output : >>> isinrange = inrange(4, 1, 7) >>> print(isinrange) Question 13. Write a function named greet(). The function greet() should ask the user's name, and then greet the user by name, with a comma between the greeting and the name. The function greet() takes one parameter: a string named greeting. For example, the following would be correct input and output: >>> greet('cheerio') What's your name? Gabriel Cheerio, Gabriel