100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
INF1511 EXAM PACK 2023 $3.31
Add to cart

Exam (elaborations)

INF1511 EXAM PACK 2023

2 reviews
 110 views  6 purchases
  • Course
  • Institution

QUESTIONS WITH ANSWERS

Preview 4 out of 98  pages

  • July 6, 2023
  • 98
  • 2022/2023
  • Exam (elaborations)
  • Questions & answers

2  reviews

review-writer-avatar

By: mdkphil06 • 6 months ago

Old question papers and no memo for May/June 2019 paper

review-writer-avatar

By: williamsgiant • 1 year ago

avatar-seller
INF1511
EXAM
PACK 2023
QUESTIONS WITH ANSWERS
Email; musyokah11@gmail.com

, Stuvia.com - The study-notes marketplace




2
INF1S11
OCTOBER/NOVEMBER 2019

Question 1 Multiple-choice questions [10]
.
INSTRUCTION· Select the correct OPTION
Question Options Answers
a) Comments m Python begin with a 1 #
2 II
3 *
4 &&&
b) What format code rs used to display 1 %a
ASCII code? 2 %s
3 %1
4 %c
c) The function which returns the data 1 datatype()
type of an object rs 2 type_()
3 obJect_O
4 data()
d) An example of an immutable 1 lists
sequence m Python rs 2 integers
3 stnngs
4 floats
e) The index value of the last element m 1 z
a hst rs 2 -1
3 0
4 1
f) rs a special method that rs 1 1mt
automatically invoked right after a 2 pnnt
new mstance of a class rs created 3 str
4 class
g) Which file access mode option 1 a+
opens a file for reading and 2 A
appends contents to the end of the 3 a
file? 4 r+
h) What will be the content of file 1 Tea Coffee Espresso
snackorder txt after the following 2 T eaCoffeeEsoresso
code has been executed? 3 TEA COFFEE ESPRESSO
4 Tea
f open (" snackordertxt", "w+")
=
Coffee
lst~['Tea', 'Coffee', 'Espresso'l
Espresso
f w£Ltelines(lst)
f close ()
1) A class that implements only the 1 data descriptor
_get_ method for an object rs 2 getter class
called a 3 fetch class
4 non-data-descriptor
J) What rs the output of 1 Tea
pr1nt(snack.get("Tea"))? 2 Tea 1
3 TEA
snack={ "Tea" .1,
"Coffee" 2, 4 1
"Espresso" 3}
-




[Please Tum Over]

Downloaded by: tebzamabalane | phamphi@webmail.co.za
Distribution of this document is illegal

,: I i :
: Stuvia.com - The Istudy-notes marketplace I I

I I I '
I I I :
.




3
INF1511
OCTOBER/NOVEMBER 2019

Question 2 Programming (30]

a) Use an if ... else statement and write a program that asks the user for mput of the time
m hours (1 to 24} for the day If the time value rs greater than 6 and less than 18, then
the program must output a comment 'Have a Happy Day',else the comment must be
'Rest Well' Please name the program and provide at least one code comment (5)

b) Write a function thedifference Wnte a program that outputs the difference between
the first and the second input numerical values The input values must be requested
from the user The values must be passed to the function, and the difference value rs
returned The output should reflect both the input and output values Please name
the program and provide at least one code comment (10)

c) Ask the user for a random number and assign the value to a variable named starting
Then using a for loop and write a program that asks the user for input of 5 numbers
Each of these numbers must be added to the m1t1al value of the variable starting. The
output must be the mmal and final value of the variable starting. Please name the
program and provide at least one code comment (5)

d) Write a program that will ask the user to input words as two strings, and will assign the
strings to variables word1 and word2 The program must jom the strings word1 and
word2 with the Jom function with a space between the strings The output must be
displayed m caprtal letters Please name the program and provide at least one code
comment ( 10)


Question 3 Object Orientation [10)

a) Consider the following code to define a class Identify the class object and a class
attribute (2)

class student:
studentnum =0
studentorder = ''
deli veryto = ''
print (student.deliveryto)

b) Given the class definition above, explain how an instance of the class rs created You
may use a coded example to clarify (2)

c) Motivate one benefit of usmg classes m programming (1)

d) Explam why garbage collecnon rs required m programmmg You may use a coded
example to clarify (1)

e) A class may have two types of methods, namely class methods and static methods
Briefly explain a difference between these two types of methods You may use a coded
example to clarify ( 4)

Downloaded by: tebzamabalane | phamphi@webmail.co.za
Distribution of this document is illegal [Please Turn Over]

, Stuvia.com - The study-notes marketplace




4
INF1511
OCTOBER/NOVEMBER 2019
Question 4 File Handling (10]

a) Explain the concept of file handling (2)


b) Explain two ways m which content may be removed from You
a fileare welcometo
include snippets of code with comments to enhance your explanation (2)


c) Consider the code below, and explain each of the 12 Imes (6)


fileexample.py
import sys
matter2 = 11' The development of programming matters'''
f = open('aboutbook.txt', 'a' )
f.wr1te("\n%s" %matter2)
f. close ()
f = open('aboutbook.txt', 1r' }
lines= f.readlines()
f. close ()
print('The contents in the file are:')
for line in lines:
sys.stdout.wr1te(l1ne}

Output:
The contents in the f .i Le are: Python is amazing Easy to learn 00
Prograrruning and web development The development of programming
matters




[Please Turn Over]

Downloaded by: tebzamabalane | phamphi@webmail.co.za
Distribution of this document is illegal

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller jpapaya. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $3.31. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

52355 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$3.31  6x  sold
  • (2)
Add to cart
Added