Skip to document

CSC1015F 2018 test2 - test

test
Course

Computer science1015 (CSC1015F)

257 Documents
Students shared 257 documents in this course
Academic year: 2018/2019
Uploaded by:
Anonymous Student
This document has been uploaded by a student, just like you, who decided to remain anonymous.
University of Cape Town

Comments

Please sign in or register to post comments.

Preview text

University of Cape Town ~~ Department of Computer Science

Computer Science 1015F ~~ 2018

Class Test 2

Marks : 35

Time : 40 minutes

Instructions:

1. Answer all questions.

2. Write your answers in PEN.

3. All questions refer to version 3 of the Python programming language.

Question 1 [8]

Examine the Q1 module listed below and answer the following questions.

#Q1

print("--Welcome to the sandwich constructor--")

print(“(Other than bread) tell us what you want”)

ing = input("Another ingredient? Y/y/N/n")

while ing== 'Y' or 'y' or 'N' or 'n':

ing = input("What ingredient do you want?")

ing = “{:$^11}”.format(ing)

print("Okay, we'll add",ing)

#ing = input("Another ingredient? Y/y/N/n")

(a) Does the last line being commented out make the while loop an infinite loop? Why or why

not?

[4]

_________________________________________________________________________

_________________________________________________________________________

_________________________________________________________________________

(b) What exactly would line 6, ing = “{:$^11}”.format(ing) do if ing =

“cheese”?

[2]

_________________________________________________________________________

(c) What are the purposes of the break , continue statements?

[2]

_________________________________________________________________________

_________________________________________________________________________

_________________________________________________________________________

_________________________________________________________________________

Question 3 [10]

(a) What is the difference between primary and secondary storage? Give an example of each.

[4]

_________________________________________________________________________

_________________________________________________________________________

_________________________________________________________________________

(b) Why are programming languages (e. Python) more suitable for writing programs than natural

(human) languages such as English?

[2]

_________________________________________________________________________

_________________________________________________________________________

_________________________________________________________________________

(c) Name two ways to convert a program from a high level language (e. Python) to machine

language. Give the differences (if any) between these two ways.

[4]

_________________________________________________________________________

_________________________________________________________________________

_________________________________________________________________________

_________________________________________________________________________

_________________________________________________________________________

_________________________________________________________________________

_________________________________________________________________________

_________________________________________________________________________

_________________________________________________________________________

_________________________________________________________________________

_________________________________________________________________________

_________________________________________________________________________

_________________________________________________________________________

_________________________________________________________________________

_________________________________________________________________________

_________________________________________________________________________

Was this document helpful?

CSC1015F 2018 test2 - test

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 2
Marks : 35
Time : 40 minutes
Instructions:
1. Answer all questions.
2. Write your answers in PEN.
3. All questions refer to version 3 of the Python programming language.