Skip to document

Csc1015f 2018 test1 memo SE

Memo for 2018 test one
Course

Computer science1015 (CSC1015F)

257 Documents
Students shared 257 documents in this course
Academic year: 2017/2018
Uploaded by:
0followers
0Uploads
4upvotes

Comments

Please sign in or register to post comments.

Related Studylists

study

Preview text

University of Cape Town ~~ Department of Computer Science

Computer Science 1015F ~~ 2018

Class Test 1

** Solutions **

Marks : 32 Time : 45 minutes Instructions: a) Answer all questions. b) Write your answers in PEN by shading in the appropriate block on the answer sheet. c) Each question is worth 2 marks. d) All questions refer to version 3 of the Python programming language.

  1. An algorithm is: a. always written in a programming language like Python. b. the best method for calculating a value. c. the only correct answer to a puzzle or problem. d. a set of instructions to be followed to solve a problem. e. a mathematical formula used in programming. d

  2. What is an example of an identifier? a. two b. 2 c. [ ] d. “two”

e. : a

Examine the Q1 module listed on the last sheet of the test and answer the following four

questions.

3. From the Q1 module , give an example of a variable?

a. “Enter a whole number: ”

b. sep

c. print

d. y

e. else

d

4. From the Q1 module , give an example of a numerical operator.

a. eval

b. %

c. y == 0

d. x

e. if

21<=20 or not -11<=-10 and 31>1 or True and not False a. False b. 0 c. True d. 1 e. (Error: invalid expression)

c 9. The following program has a logic error. How will you fix it so it prints out the correct assessment of the temperature? if age <= 0: print ("Error") elif age > 20: print ("Blue") if age > 10: print ("Red") else: print ("White") a. change "age < 30" to "age > 30" b. change the "else" to "elif age<10:" c. change the second "if" to "elif" d. change the "elif" to "if" e. use parentheses to ensure correct precedence in expressions c

  1. Suppose that a, b and c are set to specific values before this program is executed. Which combinations of values for a, b and c will result in the output value for d that is specified? if a>b: if b>c: d=b else: d=c else: if c>a: d=c else: d=a

a. a = 13, b = 12, c = 17 | d = 12

b. a = 17, b = 13, c = 12 | d = 17 c. a = 18, b = 19, c = 21 | d = 19 d. a = 9, b = 10, c = 11 | d = 11 e. a = 11, b = 12, c = 17 | d = 11

d

  1. What values for user and password would give the specified output? real_password = "password" real_name = "brian" if password==real_password: if name!=real_name: print ("one", end="!\n") else: print ("two", end="!\n") else: print ("three", end="!\n")

a. Input: user='brian' password='password' | Output: one! b. Input: user='admin' password='password123' | Output: two! c. Input: user='brian' password='password123' | Output: one! d. Input: user='admin' password='password' | Output: two! e. Input: user='brian' password='password123' | Output: three! e

  1. What values are generated by this range function? Range (-9, -1, 2)

a. -9, -7, -5, -3, - b. -9, -7, -5, - c. -3, -5, -7, - d. -1, -3, -5, - e. -1, -3, -5, -7, - b

  1. What does the following program compute? i= j=eval(input(“Enter the first number: ”)) k=eval(input(“Enter the second number: ”)) for x in range(j,k): if x % 2 != 0:
****
*****

e. *****



** *

d

Examine the Q2 module listed on the last sheet of the test and answer the following three

questions.

15. What is the exact output of the Q2a module?

a. ^^^

$ ###
$

b.

$ ^^^
$ ### $$$

c. ^^^ ###

$
$

d. ^^^###$$$$$$

e. ^^^ $$$ ###

$$$

c

  1. If the 5th line were changed to

if i > 0:

how would the output of the Q2a module change?

a. It would not change the output. b. It will result in an error. c. Would print ^^^ and ### when i is 1, 2 and 3 d. Would print

$ and ^^^ when i is 1, 2 and 3 e. Would print
$ and ### when i is 1, 2 and 3 e

Code examples for the test – you may detach this sheet.

_______________________ Question 1 ________________________________

#Q1

x = eval(input("Enter a whole number:"))

y = x % 2

if y == 0:

print(y,”not wonky”,sep=”...”)

else:

print(y,“kinda strange parents”,sep=”!!!”)

_____________________ Question 2 ______________________________________

#Q2

for i in range(4):

for j in range(3):

if i >= 2:

print(“$”,end=””)

elif i > 0:

Was this document helpful?

Csc1015f 2018 test1 memo SE

Course: Computer science1015 (CSC1015F)

257 Documents
Students shared 257 documents in this course
Was this document helpful?
University of Cape Town ~~ Department of Computer Science
Computer Science 1015F ~~ 2018
Class Test 1
** Solutions **
Marks : 32
Time : 45 minutes
Instructions:
a) Answer all questions.
b) Write your answers in PEN by shading in the appropriate block on the answer sheet.
c) Each question is worth 2 marks.
d) All questions refer to version 3 of the Python programming language.