Docsity

Test # 1 Practice Questions - Introduction to Computer Programming | CSCI 1010, Exams of Computer Science

Toggle sidebar
bg1
Computer Science 1 — CSci 1100
Fall Semester, 2012
Test 1 Overview and Practice Questions
Overview
•Test 1 will be held Thursday, September 27, 2012, 8:30 - 9:45 am.
•Location:
–Sage 3510: Lab section 1-2 (TA: Scott)
–Sage 3303: Lab sections 7,11,13,14 (TAs: Abhirami, Evan)
–Darrin 308: Lab sections 3-6,8-10,12 (TAs: Atriya, Congyang, Jason, Thiru)
–Prof. Stewart’s office, Materials 330B, 7:50 am, for students who require extra time and have given
Prof. Stewart a letter from the Dean of Students
You must go to your assigned room. If you don’t you will be assigned a 5 point penalty!
•You must have your RPI student ID with you! Anyone who does not provide an ID will lose half of the
points on the exam! This rule will be strictly enforced.
•Coverage is Lectures 1-8, Labs 1-4, HW 1-2.
•No calculators, no textbook, no classnotes, no electronics of any kind! BUT, you may bring a one-page,
double-sided, 8.5¨x 11¨
‘‘crib sheet” sheet with you. You may prepare this as you wish.
•We will assume you know (perhaps via your crib sheet) the following mathematical functions, some of
which are in the math module: abs, ceil, sqrt, trunc
•We will assume you know the following functions associated defined on data of type str: len, +,*(by an
integer), islower, isupper, capitalize, find, replace, strip, split, upper and lower.
•Coverage of lists is up through and including Section 5.9. Sections 5.10 - 5.12 will not be covered on this
test. We will assume you know the following functions defined on list types: append, insert, pop remove,
reverse, and sort. We will also assume you know how to slice lists and use the +and *operators on lists.
•Python syntax will be important on this test. On tests later in the semester it will be less important, but
not entirely ignored.
•Below are many sample questions, far more than will be on the test. Solutions to most of the problems will
be posted on-line by Tuesday morning, September 25. These posted solutions will not include problems
involving output from Python — test these out yourself!
•Please note that your solution to any question that requires you to write Python code will be at most 5-7
lines long, and may be much shorter.
•The test questions will be closely related to these practice problems and to problems from the homework,
the labs, and the lecture practice problems.
•How to study?
–Work through the sample questions, writing out solutions! You are encouraged to work with other
students.
–Review and re-do lecture exercises, lab and homework problems.
–Identify the problems that cause you difficulty and review lecture notes and background reading on
these topic areas.
–Use the Wing IDE / Python interpreter extensively to help you understand what is happening, but
practice writing solutions using pencil and paper!
•Advanced warnings:
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Test # 1 Practice Questions - Introduction to Computer Programming | CSCI 1010 and more Exams Computer Science in PDF only on Docsity!

Computer Science 1 — CSci 1100

Fall Semester, 2012

Test 1 Overview and Practice Questions

Overview

  • Test 1 will be held Thursday, September 27, 2012, 8:30 - 9:45 am.
  • Location:
    • Sage 3510: Lab section 1-2 (TA: Scott)
    • Sage 3303: Lab sections 7,11,13,14 (TAs: Abhirami, Evan)
    • Darrin 308: Lab sections 3-6,8-10,12 (TAs: Atriya, Congyang, Jason, Thiru)
    • Prof. Stewart’s office, Materials 330B, 7:50 am, for students who require extra time and have given Prof. Stewart a letter from the Dean of Students

You must go to your assigned room. If you don’t you will be assigned a 5 point penalty!

  • You must have your RPI student ID with you! Anyone who does not provide an ID will lose half of the points on the exam! This rule will be strictly enforced.
  • Coverage is Lectures 1-8, Labs 1-4, HW 1-2.
  • No calculators, no textbook, no classnotes, no electronics of any kind! BUT, you may bring a one-page, double-sided, 8.5¨x 11¨‘‘crib sheet” sheet with you. You may prepare this as you wish.
  • We will assume you know (perhaps via your crib sheet) the following mathematical functions, some of which are in the math module: abs, ceil, sqrt, trunc
  • We will assume you know the following functions associated defined on data of type str: len, +, * (by an integer), islower, isupper, capitalize, find, replace, strip, split, upper and lower.
  • Coverage of lists is up through and including Section 5.9. Sections 5.10 - 5.12 will not be covered on this test. We will assume you know the following functions defined on list types: append, insert, pop remove, reverse, and sort. We will also assume you know how to slice lists and use the + and * operators on lists.
  • Python syntax will be important on this test. On tests later in the semester it will be less important, but not entirely ignored.
  • Below are many sample questions, far more than will be on the test. Solutions to most of the problems will be posted on-line by Tuesday morning, September 25. These posted solutions will not include problems involving output from Python — test these out yourself!
  • Please note that your solution to any question that requires you to write Python code will be at most 5- lines long, and may be much shorter.
  • The test questions will be closely related to these practice problems and to problems from the homework, the labs, and the lecture practice problems.
  • How to study?
    • Work through the sample questions, writing out solutions! You are encouraged to work with other students.
    • Review and re-do lecture exercises, lab and homework problems.
    • Identify the problems that cause you difficulty and review lecture notes and background reading on these topic areas.
    • Use the Wing IDE / Python interpreter extensively to help you understand what is happening, but practice writing solutions using pencil and paper!
  • Advanced warnings:
  • We will not answer questions from students in the middle of the test unless there is a mistake in a question.
  • Once the test starts, students may not leave until they turn in their tests, and once they leave they may not return.

x = 14 - 3 ** 3 + 2 % 6 print x

y += y * len(str(y)) y

import math x = ’the answer is ’ + ( str( math.sqrt( 81 ) ) * 3 ) print x

s = ’3’ + ’4’ ’5’ s

int(s) / 10

float(s) / 10

>>> [1]3 + [3]

’aBdcSf’.lower().capitalize() + ’BdkgE’.capitalize().lower()

e = [2, 4, 1, 5, 6] e[1] = 8 e.sort() print e

e = [2, 4, 1, 5, 6] f = e[2:4] f[1] = 3 print e, ’\n’, f

  1. Assuming we type the following directly into the Python interpreter, please fill in the exactly output,

making it clear what is your answer:

t = ’ ab c-’ len(t)

x = ’32’ x * len(x)

int(x) / len(x)

a = [ 54, ’abc’, "67.5", 12 ] print a[1]

a[1] = ’def’ print a[1:3]

s = a[2] print s[-1]

name = ’monty python’ name[:-8] + name[9]

sentence = ’the quick brown fox’ print sentence[1:3] * 3 + sentence[-2:] * 3

names = [ ’graham’, ’john’, ’terry’, ’terry’, ’eric’, ’michael’ ] a = str( len( names[0] ) ) + ’2’ b = a + str( len( names[2] + names[-2] ) ) + str( len( names[1] ) ) b

  1. Assuming we type the following directly into the Python interpreter, please fill in the exactly output, making it clear what is your answer:

x = 5 y = 12 z = y-x

Please enter your name ==> Jane Q. Public Hello Jane Public!

Hint: you will need to use split

  1. Write a function that takes as input 4 numbers and returns a string listing all the numbers and their average as a float. For example:

s = spam(3, 10, 4, 2) s ’The average of 3, 10, 4, and 2 is: 4.75’

  1. Write a Python program that reads from the user the names of two people (on two separate lines of input) and prints out name of the person with the shorter name. If the two names have equal length, then print out the first name.
  2. Assume v is a list containing numbers. Write Python code to find and print the highest two values in v. If the list contains only one number, print only that number. If the list is empty, print nothing. For example, if we assigned

v = [ 7, 3, 1, 5, 10, 6 ]

then the output of your code should be something like

7 10

If we are given that

v = [ 7 ]

then the output of your code should be

7

  1. What is the output of the following program?

def spam(a1,b1,a2,b2): if (a1 == a2) and (b1 > b2): return 1 else: return 0

def egg(a1,b1,a2,b2): if (a1 > a2) and (b1 == b2): return 0 else: return 1

a1 = 3 b1 = 4 a2 = 6 b2 = 4

print spam(a2, b2, a1, b1)

print egg(a1, b1, a2, b2)

c = spam(a1, b2, a2, b1)

print z

c += egg(a1, b2, a2, b1)

print c

  1. Write Python code that takes a list of numbers, v, and outputs the positive values that are in v in increasing order, one value per line. If there are no positive values, then the output should be the string ’None’. You may assume there is at least one value in the list. As an example,

v = [ 17, -5, 15, -3, 12, -5, 0, 12, 22, -1 ]

Then the output of your code should be

12 12 15 17 22

As a second example, if

v = [ -17, -5, -15, -3, -12, -5, 0, -12, -22, -1 ]

then then output should be just

None

  1. What is the output of the following operations:

mylist = [1,4,8,12,6] x = mylist.sort() print x

mylist = [1,4,8,12,6] slice1 = mylist[2:4] slice1[0] = 20 print slice

print mylist

  1. Write a Python function, called combine2, that takes two strings containing only upper and lower case letters, and returns a string combining both input strings, with (a) all upper-case characters converted to lower-case, (b) with a space in between the strings, and (c) with the two strings in the correct alphabetical order. Here are two examples:

print combine2(’aPPle’, ’BanaNA’) apple banana print combine2(’corN’, ’Candy’) candy corn