Computer Science 217

Similar documents
Computer Science 217

Computer Science 217

Final Exam Practice Questions

CMSC 201 Computer Science I for Majors

The while Loop 4/6/16 4

CPSC 217 Midterm (Python 3 version)

Chapter 5 : Informatics practices. Conditional & Looping Constructs. Class XI ( As per CBSE Board)

THE AUSTRALIAN NATIONAL UNIVERSITY Final Examination November COMP1730 / COMP6730 Programming for Scientists

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

Exam 1, Form A CSE 231 Fall 2012 (1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

1. What is the minimum number of bits needed to store a single piece of data representing: a. An integer between 0 and 100?

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

Common Loop Algorithms 9/21/16 42

CPSC 217 L01 Midterm

CSCI 101 Midterm Sample Questions

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two 26 February 2014

Introduction to Scientific Computing Lecture 1

CMSC201 Computer Science I for Majors

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

Python Activity 7: Looping Structures WHILE Loops

A453 Task 1: Analysis: Problem: Solution:

Getting Started with Python

CS 1301 Exam 1 Fall 2013

Practice with if-then-else. COMP101 Lecture 7 Spring 2018

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?

CPSC 217 Midterm (Python 3 version)

CMSC201 Computer Science I for Majors

Midterm Exam 2B Answer key

Name: Partner: Python Activity 9: Looping Structures: FOR Loops

CS 1301 Exam 1 Fall 2013

Spring 2017 CS 1110/1111 Exam 1

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

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

CMSC 201 Spring 2018

Fundamentals of Programming (Python) Getting Started with Programming

Text Input and Conditionals

CMSC201 Computer Science I for Majors

Introduction to programming using Python

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

Fundamentals of Programming (Python) Control Structures. Sina Sajadmanesh Sharif University of Technology Fall 2017

CSE 115. Introduction to Computer Science I

Chapter Goals. Contents LOOPS

What is an Exception? Exception Handling. What is an Exception? What is an Exception? test = [1,2,3] test[3]

CSI Lab 02. Tuesday, January 21st

CS 1301 Exam 1 Fall 2014

Introduction to Programming

CS 111X - Fall Test 1

Outline. policies. with some potential answers... MCS 260 Lecture 19 Introduction to Computer Science Jan Verschelde, 24 February 2016

1. Consider the following program in a PCAT-like language.

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

Week 1 Introduction to Programming

15-110: Principles of Computing Sample Exam #1

Chapter 2. Python Programming for Physicists. Soon-Hyung Yook. March 31, Soon-Hyung Yook Chapter 2 March 31, / 52

2. Explain the difference between read(), readline(), and readlines(). Give an example of when you might use each.

Control Flow: Branching booleans and selection statements CS GMU

LOOPS. Repetition using the while statement

Comp 150 Exam 2 Overview.

CS Lab 11. Today's Objectives. Prime Number Generation Implement Diffie-Hellman Key Exchange Implement RSA Encryption

Structure and Interpretation of Computer Programs Spring 2017 Mock Midterm 1

CS Name : Grading TA:

Starting chapter 5. l First open file, and say purpose read or write inputfile = open('mydata.txt', 'r') outputfile = open('myresults.

CS 1301 Exam 1 Spring 2014

CSSE 120 Introduction to Software Development Practice for Test 1 paper-and-pencil part Page 1 of 6

Variable and Data Type I

ENGR 101 Engineering Design Workshop

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

CPTS 111, Fall 2011, Sections 6&7 Exam 3 Review

INTERMEDIATE LEVEL PYTHON PROGRAMMING SELECTION AND CONDITIONALS V1.0

CS 1301 Exam 1 Spring 2014

Lecture 02 Making Decisions: Conditional Execution

Spring 2017 CS 1110/1111 Exam 2

CS 1301 Exam 1 Fall 2009

University of Maryland College Park Dept of Computer Science CMSC106 Fall 2016 Midterm I

Definition: A data structure is a way of organizing data in a computer so that it can be used efficiently.

PIC 10A. Review for Midterm I

Test 1. CSC 121 Lecture Lecturer: Howard Rosenthal. March 4, 2014

CS 1301 Exam 1 Answers Fall 2009

(Python) Chapter 3: Repetition

Monty Python and the Holy Grail (1975) BBM 101. Introduction to Programming I. Lecture #03 Introduction to Python and Programming, Control Flow

Basic Concepts. Computer Science. Programming history Algorithms Pseudo code. Computer - Science Andrew Case 2

CS 1301 Exam 1 Fall 2014

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #16 Loops: Matrix Using Nested for Loop

CS177 Python Programming. Recitation 2 - Computing with Numbers

Introduction to Mathematical and Scientific Programming TUTORIAL WEEK 2 (MATH 1MP3) Winter 2019

PRG PROGRAMMING ESSENTIALS. Lecture 2 Program flow, Conditionals, Loops


Teaching London Computing

boolean & if-then-else

History of Computing. Ahmed Sallam 11/28/2014 1

CE151-4-AU UNIVERSITY OF ESSEX. Sample Examination Questions 2011 INTRODUCTION TO PROGRAMMING

Review Sheet for Midterm #1 COMPSCI 119 Professor William T. Verts

ECE 2030B 1:00pm Computer Engineering Spring problems, 5 pages Exam Two 10 March 2010

SAMS Programming A/B. Lecture #1 Introductions July 3, Mark Stehlik

Spring 2015 COP 3223 Section 4 Exam #1 Multiple Choice Version A

Lecture 8: Conditionals & Control Flow (Sections ) CS 1110 Introduction to Computing Using Python

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

Midterm Exam 2A Principles of Computing Fall November 10, 2014

15110 PRINCIPLES OF COMPUTING SAMPLE EXAM 2

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

CSE wi: Practice Midterm

Transcription:

Computer Science 17 Midterm Exam March 5, 014 Exam Number 1 First Name: Last Name: ID: Class Time (Circle One): 1:00pm :00pm Instructions: Neatly print your names and ID number in the spaces provided above. Pick the best answer for each multiple choice question. Answer each question by writing the correct answer in the space provided. Answer all multiple choice questions using UPPER CASE letters. This exam consists of 1 pages, including the cover. Before answering any questions count the pages and ensure that they are all present. You have 1 hour 30 minutes to complete this exam. Unless noted otherwise, each question is worth one mark. This exam is closed book. You are not permitted to use any electronic devices or reference materials. DO NOT TURN PAST THIS PAGE UNTIL YOU ARE INSTRUCTED TO BEGIN Version A Page 1 of 1 Exam Number 1

1. (1 marks) Create a program that finds the smallest factors of a collection of integers entered by the user. When the program runs the user will be prompted to enter an integer. If the integer is or greater then the program should display the smallest factors of the integer, with one factor appearing on each line. If the integer entered by the user is less than then the program should terminate. The program should allow the user to continue entering integers until a value less than is entered. The last line of output in your program should be a meaningful message that indicates how many numbers were factored. The smallest factors of an integer, n, can be determined using the following steps: Initialize factor to two As long as factor is less than or equal to n If n is evenly divisible by factor then Conclude that factor is a factor of n Divide n by factor Otherwise Increase factor by one Sample input and output (user input is shown in bold): Enter an integer (less than to quit): 1 3 Enter an integer (less than to quit): 77 7 11 Enter an integer (less than to quit): 3880800 3 3 5 5 7 7 11 Enter an integer (less than to quit): 0 3 numbers were factored successfully. Print your answer on the next page. Do not try to print your answer on this page. 0 Version A Page of 1 Exam Number 1

Print your answer to question 1 on this page. Version A Page 3 of 1 Exam Number 1

. The type of electronic switch commonly used in computers today is known as a: A. Bridge B. Bus C. Relay D. Transistor E. Vacuum Tube 3. The Dining Philosopher s Problem demonstrates a challenge that occurs in which area of computer science? A. Computer Vision B. Distributed Systems C. Human Computer Interaction D. Information Security E. Theory of Computation 4. Which of the following is an example of an artificial intelligence system? A. Abacus B. Babbage C. Bloom D. ENIAC E. Watson 5. List two of the three components that connect directly to the central processing unit in a modern computer architecture. Note that motherboard and bus are not acceptable answers. You must indicate a component, not the connection to the component. 6. Consider the following statement: The complexity for minimum component cost has increased at a rate of roughly a factor of two per year Certainly over the short term this rate can be expected to continue, if not increase. Over the longer term, the rate of increase is a bit more uncertain, although there is no reason to believe it will not remain nearly constant for at least 10 years. This statement is known as: 7. Which of the following answers best describes the ability you would expect to have at a synthesis level of competence? A. The ability to combine two distinct ideas to solve a problem B. The ability to compare the costs and benefits of two different solutions C. The ability to predict the consequences of an action D. The ability to separate a system into distinct components E. The ability to solve a problem by following a known pattern Version A Page 4 of 1 Exam Number 1

8. A finite sequence of effective steps that solve a problem is known as: A. a computer program B. a flowchart C. a recipe D. an algorithm E. an executable file 9. Provide an example of an illegal variable name. Explain why the name you have provided is illegal in one sentence or less. Note that you should only consider whether or not Python will allow you to use the variable name. A name may still be legal even if it is stylistically poor. Illegal variable name: Explanation: 10. In the classic game Warcraft II, the unit editor allowed you to assign up to 65535 ( 16-1) hit points to a unit. Given this information, it is most likely that the number of hit points was being stored in a: A. bit B. byte C. double word D. half word E. word 11. Consider the following code segment: a = input("enter a: ") b = input("enter b: ") c = a + b print(c) What will be displayed if the user enters 3 for a and 4 for b? A. 3 B. 4 C. 7 D. 34 E. None of the above answers are correct Version A Page 5 of 1 Exam Number 1

1. Assume that a variable named pi has been created and initialized to 3.1415965359. Which of the following statements will display 3.1416? A. print("%.4f" % pi) B. print("%.4pi") C. print("%4.f" % pi) D. print("%4f" % pi) E. print(pi) 13. The operator with highest precedence is: A. = B. >= C. and D. not E. or 14. Which type of Python error does not result in an error message being reported by Python? A. Logic errors B. Runtime errors C. Syntax errors D. Type errors E. Value errors 15. Convert 16 base 10 to binary: Version A Page 6 of 1 Exam Number 1

16. Convert 101010100001011111 to hexadecimal: 17. ( marks) Convert AA base 13 to base 5: Version A Page 7 of 1 Exam Number 1

18. Which of the following is the truth table for the logical expression A and not B or not A and not B? A. A B Result 0 0 0 0 1 0 1 0 1 1 1 0 B. A B Result 0 0 0 0 1 1 1 0 1 1 1 0 C. A B Result 0 0 1 0 1 0 1 0 0 1 1 0 D. A B Result 0 0 1 0 1 0 1 0 1 1 1 0 E. A B Result 0 0 0 0 1 1 1 0 1 1 1 0 19. How many rows will there be in the truth table for the logical expression not A and not B and not C? A. 3 B. 7 C. 8 D. 15 E. 16 Version A Page 8 of 1 Exam Number 1

0. Which of the following code segments is an example of a nested if statement? A. if a == b : print(a) B. if a == b : print(a) if a == c : print(c) C. if a == b : print(a) if c == d : print(c) D. if a > 0: a = a - 1 elif a < 0: a = a + 1 E. if a == b : print(a) else : print(b) Consider the following Python program: w = int(input("enter w: ")) x = int(input("enter x: ")) if w < x: w = x + 1 if x < w: x = w + 1 print(w, x) 1. If the user enters 5 for w and 1 for x, then the output will be:. If the user enters 1 for w and 5 for x, then the output will be: 3. If the user enters for w and for x, then the output will be: 4. Which type of loop always executes one or more times? A. For loop B. Post-tested loop C. Pre-tested loop D. While loop E. More than one of the above answers is correct Version A Page 9 of 1 Exam Number 1

Consider the following Python program: a = int(input("enter an integer: ")) if a < 0: a = a + 1 if a == 0: a = a + 1 elif a > 0: a = a + elif a > 0: a = a - 1 if a == 0: a = a - 1 else: a = a - print(a) 5. If the user enters - for a, then the output will be: 6. If the user enters 0 for a, then the output will be: 7. If the user enters for a, then the output will be: Consider the following loop: j = 10 while j >= 5: print("x") j = j - 1 8. Which of the following for loops will generate the same output as the loop shown previously? A. for j in range(10, 5): print("x") B. for j in range(10, 5, -1): print("x") C. for j in range(10, -1, -): print("x") D. for j in range(0, 5): print("x") E. for j in range(-1, -5, -1): print("x") Version A Page 10 of 1 Exam Number 1

Consider the following code segment: a = int(input("enter an integer: ")) i = 0 j = 1 while i < a: if i % 3!= 0: print(i) else: j = j * i = i + 1 print(j) 9. If the user enters 1 for a then the output will be: 30. If the user enters 3 for a then the output will be: 31. If the user enters 6 for a then the output will be: Consider the following code segment: a = int(input("enter an integer: ")) i = count = 1 while i <= a: b = True for j in range(, i // + 1): if i % j == 0: b = False if b == False: count = count + 1 else: print(i) i = i + 1 print(count) 3. If the user enters 1 for a then the output will be: 33. If the user enters 3 for a then the output will be: 34. If the user enters 6 for a then the output will be: Version A Page 11 of 1 Exam Number 1

35. (4 marks) The following program is supposed to read floating point numbers from the user until zero is entered. After the zero is entered the program should display the average of the entered values along with the distance from the smallest value to the largest value. For example, if the user enters the values 5.5,, -.5, -1 and 0 then the program should report an average of 1.0 and a distance of 8.0. Unfortunately the program contains (at least) 4 bugs. The comments are all correct, and describe what the program is supposed to do. Circle each of the 4 bugs (and only the bug) and write one sentence or less next to each bug indicating what you would need to do to fix it. Note that in this context a bug is defined to be something that will stop the program from generating a correct result, or causes the program to crash. It does not include stylistic issues, differences in output messages, spelling mistakes in prompts, etc. # Read the first value value = int(input("enter a number (0 to quit): ")) # Initialize the largest and smallest values using the first input largest = value smallest = value # Initialize the count and the total count = -1 total = 0 # Process each value entered, until the user enters zero. while value!= 0.0 : # Keep track of the number of values entered and the total count = count + "1" total = total + value # Keep track of the largest and smallest values entered so far if value > largest: largest = value if value < smallest: smallest = value # Read the next input value value = float(input("enter a number (0 to quit): ")) # Compute and display the results. if count == 0: # Handle the case where no values are entered print("no values were entered.") else: # Display the average and distance from the smallest value to # the largest value print("the average of the values is", total / count) print("the distance between the largest and smallest values is", \ largest + smallest) Version A Page 1 of 1 Exam Number 1