Test 2. 1 True or False. CSCE 110. Introduction to Programming 2

Similar documents
Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Chapter 5. Selection 5-1

CSC 221: Computer Programming I. Fall 2011

Programming Your App to Make Decisions: Conditional Blocks

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

Introduction to Python

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

Computers. An Introduction to Programming with Python. Programming Languages. Programs and Programming. CCHSG Visit June Dr.-Ing.

Algorithm & Flowchart & Pseudo code. Staff Incharge: S.Sasirekha

River Dell Regional School District. Computer Programming with Python Curriculum

McGraw-Hill The McGraw-Hill Companies, Inc.,

CSCE 110 Programming I Basics of Python: Variables, Expressions, and Input/Output

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements

Object Oriented Software Design

#820 Computer Programming 1A

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...

Python Programming: An Introduction To Computer Science

Informatica e Sistemi in Tempo Reale

PROG0101 Fundamentals of Programming PROG0101 FUNDAMENTALS OF PROGRAMMING. Chapter 3 Algorithms

Exercise 1: Python Language Basics

VHDL Test Bench Tutorial

Python Programming: An Introduction to Computer Science

Object Oriented Software Design

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Introduction to Python

Database Programming with PL/SQL: Learning Objectives

Introduction to Programming (in C++) Loops. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC

Example. Introduction to Programming (in C++) Loops. The while statement. Write the numbers 1 N. Assume the following specification:

Selection Statements

Fundamentals of Programming and Software Development Lesson Objectives

Chapter 1: Key Concepts of Programming and Software Engineering

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Two-way selection. Branching and Looping

2) Write in detail the issues in the design of code generator.

Introduction to Computer Science I Spring 2014 Mid-term exam Solutions

Some programming experience in a high-level structured programming language is recommended.

6.1 The Greatest Common Factor; Factoring by Grouping

PL / SQL Basics. Chapter 3

QUIZ-II QUIZ-II. Chapter 5: Control Structures II (Repetition) Objectives. Objectives (cont d.) 20/11/2015. EEE 117 Computer Programming Fall

Exercise 4 Learning Python language fundamentals

The programming language C. sws1 1

Problem Solving Basics and Computer Programming

Lecture 2 Notes: Flow of Control

ARIZONA CTE CAREER PREPARATION STANDARDS & MEASUREMENT CRITERIA SOFTWARE DEVELOPMENT,

Sources: On the Web: Slides will be available on:

Welcome to Introduction to programming in Python

Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A

Topic 11 Scanner object, conditional execution

Computer Programming I

Elementary Number Theory and Methods of Proof. CSE 215, Foundations of Computer Science Stony Brook University

Computational Mathematics with Python

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

CHAPTER 18 Programming Your App to Make Decisions: Conditional Blocks

DATA 301 Introduction to Data Analytics Microsoft Excel VBA. Dr. Ramon Lawrence University of British Columbia Okanagan

Data Structures. Algorithm Performance and Big O Analysis

Computer Science for San Francisco Youth

AQA GCSE in Computer Science Computer Science Microsoft IT Academy Mapping

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

Moving from CS 61A Scheme to CS 61B Java

Computer Programming I

Computational Mathematics with Python

Chapter 8 Selection 8-1

VISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0

Visual Logic Instructions and Assignments

Arrays. number: Motivation. Prof. Stewart Weiss. Software Design Lecture Notes Arrays

Functional Programming. Functional Programming Languages. Chapter 14. Introduction

Iteration CHAPTER 6. Topic Summary

Welcome to Basic Math Skills!

Previously, you learned the names of the parts of a multiplication problem. 1. a. 6 2 = 12 6 and 2 are the. b. 12 is the

Python Evaluation Rules

Keil C51 Cross Compiler

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

6.080 / Great Ideas in Theoretical Computer Science Spring 2008

if and if-else: Part 1

Chapter 3 Writing Simple Programs. What Is Programming? Internet. Witin the web server we set lots and lots of requests which we need to respond to

Python Programming: An Introduction to Computer Science

Fundamentals of Java Programming

Introduction to Python

6. Control Structures

ALGORITHMS AND FLOWCHARTS

This loop prints out the numbers from 1 through 10 on separate lines. How does it work? Output:

Programming and Software Development CTAG Alignments

VB.NET Programming Fundamentals

Writing Simple Programs

Computer Science 1 CSci 1100 Lecture 3 Python Functions

Chapter 2: Algorithm Discovery and Design. Invitation to Computer Science, C++ Version, Third Edition

The previous chapter provided a definition of the semantics of a programming

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

CS 111 Classes I 1. Software Organization View to this point:

Symbol Tables. Introduction

Outline. multiple choice quiz bottom-up design. the modules main program: quiz.py namespaces in Python

Parameter passing in LISP

So far we have considered only numeric processing, i.e. processing of numeric data represented

IS0020 Program Design and Software Tools Midterm, Feb 24, Instruction

Regular Expressions with Nested Levels of Back Referencing Form a Hierarchy

IVR Studio 3.0 Guide. May Knowlarity Product Team

Curriculum Map. Discipline: Computer Science Course: C++

Transcription:

CSCE 110. Introduction to Programming 2 Test 2 Professor:Joseph Hurley Exam Version A 1 True or False Fill in the bubble for "A" if the answer is True. Fill in the bubble for "B" if the answer is False. 1. True/False: Nested decision structures are the only way to test more than one condition. 2. The line if x = y: will evaluate to true for x = 4 and y = 4. 3. Short-circuit evaluation is performed only with the "and" operator. 4. Reducing duplication of code is one of the advantages of using a loop structure. 5. In owcharting, the decision structure and the repetition structure both use the diamond symbol to represent the condition that is tested. 6. In Python, you are more likely to get an innite loop in a for structure than in a while structure. 7. In a nested loop, the inner loop goes through all of its iterations for every single iteration of an outer loop. 8. Assume you have a nested loop structure with an outer loop and an inner loop. The outer loop will repeat n times and the inner loop will repeat m times each time the outer loop repeats. So, you will have a total of n m repetitions of the inner loop. 9. The randrange function returns a randomly selected value from a specic sequence of numbers. 10. True/False: The math function, ceil(x), returns the smallest integer that is less than or equal to x. 11. When a piece of data is read from a le, it is copied from the le into RAM. 12. In Python, if you try to access a le that does not exist, it will always cause an error. 13. It is possible to create a while loop that determines when the end of a le has been reached. 14. A function can return multiple values only if they are all of the same type (int, string, bool, etc). 15. A le object may be associated with multiple les. 2-1

2 Multiple Choice Fill in the bubble that corresponds to your answer choice. 16. What is the disadvantage of coding in one long sequence structure? (A) Duplicated code makes the program faster to write. (B) Writing a long sequence of statements is error prone. (C) If parts of the duplicated code have to be corrected, the correction has to be made many times. (D) It does not make use of decision structures. (E) Both B and C 17. Which of the follwoing is the correct format for a while loop in Python? (A) while x < 5 and x > 0 (B) while x < 5 and > 0: (C) while x <5 && x > 0: (D) while x < 5 and x > 0: (E) while: x < 5 and x > 0; 18. What are the values that the variable num contains through the iterations of the following for loop? for num in range(2, 9, 2): (A) 2, 3, 4, 5, 6, 7, 8, 9 (B) 2, 5, 8 (C) 2, 4, 6, 8 (D) 1, 3, 5, 7, 9 (E) 1, 4, 7, 9 19. What are the values that the variable num contains through the iterations of the following for loop? for num in range(4): (A) 0, 1, 2, 3 (B) 1, 2, 3, 4 (C) 0, 1, 2, 3, 4 (D) 1, 2, 3 (E) 0, 2, 4 20. A variable used to keep the running total is called a(n)... (A) Accumulator (B) Total 2-2

(C) Average (D) Sum (E) Grand Total 21. The rst input operation is called the, and its purpose is to get the rst input value that will be tested by the validation loop. (A) priming read (B) rst input (C) default read (D) loop validation (E) loop set read 22. What is the programming structure that causes a statement or a set of statements to execute repeatedly? (A) Sequence (B) Decision (C) Module (D) File (E) Repetition 23. When will the following loop terminate? while keep_on_going!= 999 : (A) When keep_on_going refers to a value less than 999 (B) When keep_on_going refers to a value greater than 999 (C) When keep_on_going refers to a value that is an integer (D) When keep_on_going refers to a value not equal to 999 (E) When keep_on_going refers to a value equal to 999 24. In Python, the variable in the for clause is referred to as the because it is the target of an assignment at the beginning of each loop iteration. (A) target variable (B) loop variable (C) for variable (D) count variable (E) terminating variable 25. Which of these represents an example of adding variable number to an accumulator variabletotal? (A) total + number = total 2-3

(B) number += number (C) total = total + number (D) total += number (E) Both C & D 26. The Python library functions that are built into the Python, such as print() can be used by simply calling the function, without importing a module. (A) code (B) default module (C) compiler (D) linker (E) interpreter 27. Python comes with functions that have been already prewritten for the programmer. (A) library (B) standard (C) built-in (D) custom (E) interpeted 28. Which of the following statements tells the interpeter to load the random module into memory? (A) load random module (B) load module random (C) load random (D) import random (E) import module random 29. Which of the following will assign a random number in the range of 1 through 50 to the variable number? (A) number = random.randint(0,50) (B) number = random(0,50) (C) number = random.randomrange(0,50) (D) number = random.range(0,50) (E) None of the above 30. What is the result of the following statement? x = random.randint(5, 15) * 2 (A) A random integer from 10 to 30, multiplied by 2, assigned to the variable x (B) A random integer from 5 to 15 assigned to the variable x 2-4

(C) A random integer from 5 to 15, multiplied by 2, assigned to the variable x (D) A random integer from 5 to 15, selected in 2 steps, assigned to the variable x (E) A random integer from 5 to 15, raised to the power of 2, assigned to the variable x 31. What type of value is returned by the uniform function? (A) bool (B) list (C) int (D) double (E) oat 32. The is_prime(num) function is what type of function? (A) boolean (B) even (C) binomial (D) math (E) deciding 33. What does this function do? def x(y): for x in range(2, y): if y % x == 0: return True return False (A) Determines whether y is even or odd (B) Determines if x is an integer (C) Returns smallest possible divisor (D) Determines whether y is prime (E) Determines if y = 0 34. What allows for easier code reuse between two or more programs? (A) moderators (B) modules (C) procedures (D) value returning functions (E) functions ANS: B 2-5

35. You have a group of conditional statements, each with associated actions to perform if the condition is true. In the case that you want only one of the cases to be true, you should use the control structure (A) if (B) if/else (C) if/elif/else (D) if/end (E) if/elif/end 36. What does the following line mean? number1, number2 = getmaxandmin() (A) The function getmaxandmin() takes two arguments, number1 and number2 (B) The function getmaxand Min() returns one argument, saved in both number1 and number2 (C) The statement causes a syntax error. (D) The statement causes a runtime error. (E) The function getmaxandmin() returns two arguments, saved in number1 and number2 respectively. 37. Given the following denition for the magic function, what does the statement print(magic(15)) ouptut? def magic(num): return num + 3 * 25 (A) 70 (B) 280 (C) 90 (D) 450 (E) 455 38. What happens when a piece of data is written to a le? (A) Data is copied from a variable in RAM to a le. (B) Data is copied from a variable in the program to a le. (C) Data is copied from the program to a le. (D) Data is copied from a le object to a le. (E) Data is copied from a string to a le. 39. Which line creates a connection between a program and a le "x.txt"? (A) read("x.txt") (B) import("x.txt") (C) "x.txt".open() (D) open("x.txt", "r") 2-6

(E) process("x.txt) 40. What type of le allows a program to jump directly to a piece of data without reading all data before it? (A) Sequential (B) Random-Access (C) Text-Based (D) Cached (E) Indexed ANS: B 41. Which mode specier will clear the contents of the le if it previously exists or create a new le if it previously does not exist? (A) 'r' (B) 'a' (C) 'd' (D) 'w' (E) 'e' 42. A control structure is. (A) A logical design that controls the order in which a set of statements execute. (B) A statement that ends execution of your program (C) A statement that controls output (D) A way of obtaining input (E) A shortcut to programming functions 43. Multiple complete boolean statements can be combined using the logical operators "and" and "or" to create expressions. (A) multiple (B) logical (C) mathematical (D) compound (E) combinatory 44. When using the "and" operator. (A) All subexpressions must evaluate to False for the entire expression to evaluate to True. (B) Only one subexpression must evaluate to False for the entire expression to evaluate to True. (C) All expressions must evaluate to True for the entire expression to evaluate to True. (D) Only one subexpression must evaluate to True for the entire expression to evaluate to True. 2-7

(E) None of the Above 45. Which line properly determines if a value x is in the range of 0 to 100? (A) if x >= 0 or x <= 100: (B) if x <= 0 or x >= 100 (C) if x >= 0 and <= 100: (D) if x >= 0 and x <=100: (E) while x <= 100 or x >= 0: 46. Assume x = 5, y = 4, and z =6 result = (x < y) and (z > x). What is the data type of result? (A) True (B) 5 (C) Boolean (D) Int (E) None of the above 47. Which of the following ranges has a length of 4? (A) range(10,5,-1) (B) range(4) (C) range(55,59) (D) range(1,8,2) (E) All of the above 48. The following loop is an example of: x=0; while x == 0: x = 4 % 2 (A) A control statement (B) An innite loop (C) A for loop (D) A multiconditional while loop (E) A mathematical loop ANS: B 49. Given the following code, which value would be printed? for y in range(2): for x in range(2): print(x ** y) (A) 1 (B) 2 2-8

(C) 1 2 (D) 1 4 (E) None of the above 50. What does the following statement do?: print(random.randrange(20,30)) (A) Prints random integer in range 1 through 30 (B) Prints a random integer in range 20 through 29 (C) Prints random integer in range 2 through 5 (D) Prints a random integer in range 20 through 50 (E) None of the above ANS: B 2-9