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

Similar documents
CS 115 Exam 2 (Section 1) Spring 2017 Thu. 03/31/2017

CS 115 Exam 2 (Section 1) Fall 2017 Thu. 11/09/2017

CS 115 Exam 3, Fall 2011

CS 115 Exam 3, Fall 2016, Sections 5-8

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming

CS 115 Exam 3, Fall 2015, Sections 1-4

CS 115 Exam 3, Fall 2016, Sections 1-4

CS 115 Exam 3, Spring 2014

CS 115 Exam 3, Spring 2015, Sections 1-4

Chapter 2 Writing Simple Programs

Exploring Python Basics

First Midterm Exam CS164, Fall 2007 Oct 2, 2007

CS 1301 Exam 1 Spring 2014

Variable and Data Type I

Fundamentals of Programming (Python) Getting Started with Programming

Exploring Python Basics

CS 351 Exam 3, Fall 2011

CS 1301 Exam 1 Spring 2014

Getting Started with Python

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?

Practice with Functions

Variable and Data Type I

Programming. We will be introducing various new elements of Python and using them to solve increasingly interesting and complex problems.

SI Networked Computing: Storage, Communication, and Processing, Winter 2009

Python - Week 3. Mohammad Shokoohi-Yekta

AP Computer Science. if/else, return values. Copyright 2010 by Pearson Education

Encapsulation in Java

CHAPTER 2: Introduction to Python COMPUTER PROGRAMMING SKILLS

CS 1301 Exam 1 Spring 2015

Summary of the Lecture

CSCI 3300 Assignment 4

Introduction to computers and Python. Matthieu Choplin

CS110 Introduction to Computing Fall 2006 Midterm Exam

Python Activity 5: Boolean Expressions and Selection Statements

1. Word Analysis: (Which nouns suggest a need for memory (a variable) and which verbs suggest a need for action (a function maybe).

CSCE 110 Programming I Basics of Python: Lists, Tuples, and Functions

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

COMP 102: Test August, 2017

Computer Programming, I. Laboratory Manual. Experiment #3. Selections

Motivations. Chapter 3: Selections and Conditionals. Relational Operators 8/31/18. Objectives. Problem: A Simple Math Learning Tool

CS 351 Exam 3 Mon. 5/11/2015

Benchmark Excel 2010 Level 1, Chapter 5 Rubrics

Module 3 SELECTION STRUCTURES 2/15/19 CSE 1321 MODULE 3 1

CS 351 Exam 1, Fall 2010

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]

THE AUSTRALIAN NATIONAL UNIVERSITY Mid Semester Examination September COMP1730 / COMP6730 Programming for Scientists

Structure and Interpretation of Computer Programs Spring 2017 Mock Midterm 1

CS 450 Exam 2 Mon. 11/7/2016

CSCI 131, Midterm Exam 1 Review Questions This sheet is intended to help you prepare for the first exam in this course. The following topics have

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

CS 351 Exam 3, Fall 2013

Control Flow: Loop Statements

CS 2316 Individual Homework 1 Python Practice Due: Wednesday, January 20 th, before 11:55 PM Out of 100 points

Selection statements. CSE 1310 Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington

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

Midterm I - Solution CS164, Spring 2014

CS 1301 Exam 1 Fall 2011

Chapter 3 Selections. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved.

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!

Lecture 4: Simple Input-Calculate-Output Programs

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

ENGR 102 Engineering Lab I - Computation

CSE 143, Winter 2010 Midterm Exam Wednesday February 17, 2010

Programming with Python

Flow of programming execution control is sequential unless a control structure is used to change that there are 2 general types of

Lecture 4: Conditionals

CSCI 111 Midterm 1, version A Exam Fall Solutions 09.00am 09.50am, Tuesday, October 13, 2015

Connexions module: m Linear Equations. Rupinder Sekhon

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

CS 351 Exam 2, Fall 2012

RETURN X return X Returning a value from within a function: computes the value of variable exits the function and returns the value of the variable

COMP 102: Test August, 2017

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

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

Midterm 1 1 /8 2 /9 3 /9 4 /12 5 /10. Faculty of Computer Science. Term: Fall 2018 (Sep4-Dec4) Student ID Information. Grade Table Question Score

Selection Statements. Pseudocode

Scripting Languages. Python basics

Lecture 6. Assignments. Java Scanner. User Input 1/29/18. Reading: 2.12, 2.13, 3.1, 3.2, 3.3, 3.4

CS 1301 CS1 with Robots Summer 2007 Exam 1

CS1150 Principles of Computer Science Boolean, Selection Statements

15-110: Principles of Computing Sample Exam #1

EECE.2160: ECE Application Programming Spring 2016 Exam 1 Solution

CS 1301 Exam 1 Answers Fall 2009

Semester 2, 2018: Lab 1

CS-211 Fall 2017 Test 1 Version A Oct. 2, Name:

CS 1301 Exam 1 Fall 2010

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

CS 1301 Exam 1 Fall 2014

Welcome to the Using Objects lab!

Short Answer Questions (40 points)

4 Decision making in programs

CS 1301 Exam 1 Fall 2009

CS 115 Exam 3, Spring 2011

Introduction to Functions. Intro to Computer Science CS1510 Dr. Sarah Diesburg

CS 450 Exam 2 Mon. 4/11/2016

CSC A20H3 S 2011 Test 1 Duration 90 minutes Aids allowed: none. Student Number:

RETURN X return X Returning a value from within a function: computes the value of variable exits the function and returns the value of the variable

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

CS164 Second Midterm Exam Fall 2014

There are two ways to use the python interpreter: interactive mode and script mode. (a) open a terminal shell (terminal emulator in Applications Menu)

Transcription:

CS 115 Exam 1, Fall 2015 Thu. 09/24/2015 Name: Section: Rules and Hints You may use one handwritten 8.5 11 cheat sheet (front and back). This is the only additional resource you may consult during this exam. No calculators. Explain/show work if you want to receive partial credit for wrong answers. As long as your code is correct, you will get full credit. No points for style. When you write code, be sure that the indentation level of each statement is clear. Grade Problem Your Score Max Score Problem 1: Trace code 35 Problem 2: Choose the correct answer 10 Problem 3: Write snippets of code 25 Problem 4: Write a complete program 30 Total 100

Problem 1: Trace code (35 points) What will print to the screen when each of the following snippets of code is executed in PyCharm or in the Online Python Tutor? Be very clear with spacing, line breaks, etc. Treat each sub-problem as an independent question. Problem 1A (4 points) x = 120 print (x, 'x ') Problem 1B (4 points) color = 'red ' print ('I think ', color, 'is a pretty color.', sep = '!') Problem 1C (4 points) a = 6 % 4 b = 6 // 4 c = 6 / 4 d = 6.0 // 4 print (a, b, c, d) 2

Problem 1D (6 points) s1 = ' Sonoma ' print (s1) s2 = s1 s1 = 'State ' print (s1, s2) s3 = s1 s1 = s2 s2 = s3 s3 = ' University ' print (s1, s2, s3) Problem 1E (4 points) for i in range (7): print (i - 1) 3

Problem 1F (10 points) k=0 for j in range (1, 4): for i in range (3): print (i, j) k = k + (i - j) print (k) Problem 1G (3 points) y = 24 if y > 24: print ('Yay ') elif y!= 24: print ('Boo ') else : print ('Shoo ') 4

Problem 2: Choose the correct answer (10 points) Choose the letter corresponding to the correct answer for each of the following snippets of code when it is executed in PyCharm or in the Online Python Tutor. Problem 2A (3 points) What is the output of this program? a = '2' b = '3' c = a + b print (c) A. 5 B. 23 C. 2 3 D. ab Problem 2B (4 points) Assume i is an integer. Which one of these statements will yield a syntax error? A. val = input ( print (' Enter value for person ', i) ) B. val = input ( ' Enter value for person ', i ) C. val = input ( ' Enter value for person ' + str ( i) ) D. val = print ( input ( ' Enter value for person ' ), i ) Problem 2C (3 points) Which of the following statements would evaluate the following condition : variable x is not equal to variable z A. if (x!= z ): B. if not (x == z): C. if (x > z) or (x < z): D. A and B. E. B and C. F. A and C. G. A, B and C 5

Problem 3: Write snippets of code (25 points) Write snippets of code to do the following. Your code should only print the requested output. You will lose points for printing additional output. You can assume that all your snippets are enclosed within a main function and that any necessary libraries have been imported. You only need to write the specific lines of code that accomplish each task. Problem 3A (15 points) Write a snippet of code that will ask the user for their height in inches and weight in pounds. It should print their height in meters (m.), mass in kilograms (kg.) and the body mass index (BMI). Use these conversion formulas: 1 kg is 2.2 pounds 1 inch is.0254 m BMI = (weight in kilograms)/ (Height in meters x Height in meters ) You can assume that the user enters positive numeric values. 6

Problem 3B (10 points) Based on the value of body mass index (BMI) computed in previous question, report the weight category as follows: BMI under 18.5: underweight BMI at least 18.5 and under 25: normal weight BMI at least 25 and under 30: overweight BMI of 30 or above: overweight You may employ the same variable name you used in previous question or use the variable name bmi to denote the BMI. 7

Problem 4: Write a complete program (30 points) For this problem, you must write a complete program. That includes a docstring, a def main(), any necessary library imports, etc. Read the instructions carefully before you start coding! If you get stuck, try to maximize your partial credit. Your program should: Ask the user how many temperatures they will enter. You may assume they enter an integer. If this integer is not positive, print an error message and do not print any further output. Prompt the user for that many temperatures in Celsius (C). Convert each temperature to Fahrenheit using the following formula, where C is the Celsius temperature: 9 5 C + 32 Print the average temperature in Fahrenheit Print the number of temperatures that were below freezing (0 degrees Celsius) Print the minimum temperature in Celsius Here is an example of what your program might do. User input is italicized and underlined. Enter number of temperatures: 4 Enter temperature (in Celsius): -15.67 Temperature in Fahrenheit: 3.7940000000000005 Enter temperature (in Celsius): 24 Temperature in Fahrenheit: 75.2 Enter temperature (in Celsius): 47.3 Temperature in Fahrenheit: 117.14 Enter temperature (in Celsius): -5.22 Temperature in Fahrenheit: 22.604 Average temperature = 54.6845 Fahrenheit Number of temperatures below freezing = 2 Minimum temperature = -15.67 Celsius 8

Problem 4, continued 9