[go: up one dir, main page]

0% found this document useful (1 vote)
464 views28 pages

INF1511 Tutorial+201

INF1511 Tutorial+201 Assignment answers

Uploaded by

claudz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
464 views28 pages

INF1511 Tutorial+201

INF1511 Tutorial+201 Assignment answers

Uploaded by

claudz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

INF1511/201/1/2018

Tutorial Letter 201/1/2018

Visual Programming 1
INF1511

Semester 1

School of Computing

IMPORTANT INFORMATION:
This tutorial letter contains ASSIGNMENT SOLUTIONS for 2018 Semester 1.

All other important information is sent to your myLife account and is available on
the module INF1511 website.
CONTENTS

Page

Assignment 1 MCQ [20] ......................................................................................................................... 3


Assignment 2 PDF [15] .......................................................................................................................... 8
Assignment 3 MCQ [20] ....................................................................................................................... 10
Assignment 4 PDF [15] ........................................................................................................................ 13
Assignment 5 MCQ [20] ....................................................................................................................... 15
Assignment 6 PDF [20] ........................................................................................................................ 19
Assignment 7 PDF [15] ........................................................................................................................ 21
Assignment 8 PDF [15] ........................................................................................................................ 25

2
INF1511/201/2/2018

Assignment 01 MCQ [20]

Question Option Answer

1. Comments in Python begin with 1 /


a… 2 #
3 *
4 //
2. Which of the following 1 Ordered sequence of values.
statements describes the List 2 Ordered, immutable sequence of
data type? values.
3 Unordered collection of
values.
4 Sequence of Unicode
characters.
3. What is the output of the following 1 I love,Python!
statement? I love Python!
2
print("I love ", "Python! 3 I lovePython!
") 4 I love
Python!
4. Which statement correctly 1 Literals are used to perform a specific
describes Literals? function in a program.
2 Literals should be declared before they
can be used.
3 Strings or numbers that appear directly
in a program.
4 Literals can be used as regular
identifiers.
5. The function which returns the 1 data()
data type of an object is … 2 object()
3 datatype()
4 type()
6. The function used to generate a 1 range()
random number in Python is … 2 random()
3 print()
4 choice()

3
7. The function used to receive 1 str()
input from users is … 2 input()
3 print()
4 type()
8. What is the value of num3 after 1 8
executing the following code? 2 12
num1=2 3 10
num2=4
if(num1%num2 != 0): 4 6
num3=2*num1+num2
elif(num2%num1 >0):
num3=num1+num2*2
else:
num3=num1+num2

9. The output of the following code 1 0 1 2 3 4


is: 2 0 1 2 3 4 5
3 1 2 3 4 5
For i in range(5):
print(i) 4 2 3 4 5 6
5 3 4 5 6 7

10. Which is a membership operator 1 not


in Python? 2 not in
3 and
4 or
1 1 2 3 4
11. What is the output of the
following for loop? 2 1 2 3 4 5
3 1
for i in range(1,5): 2 2
for j in range(1,i+1): 3 3 3
print(i,end=' ') 4 4 4 4
print('') 5 5 5 5 5
4 1
2 2
3 3 3
4 4 4 4

4
INF1511/201/2/2018

12. What is the output of the following 1 3 5


code? 1 3 5 7
2
i=1;
3 3 5 7 9
while i < 8:
i = i+2 4 1 3 5
print(i,end=' ')

13. Which statement about Python is 1 Python does not support


true? object–oriented programming.
2 Python is a compiled
language.
3 In Python there is no need
to define variable data
type.
4 A Python variable name can
start with a digit.
14. Consider the following statement: 1 The value of x is 4.5

x=4.5 2 The value of x is 4


3 The value of x is %d %x
print("The value of x is
%d" %x) 4 Python will give an error
The output is:

15. x=5%2. The value of x is …. 1 1


2 2
3 2.5
4 5
5 1.5
16. What would the following 1 ['Tim', 'Cat']
statement return? ['Sarah', 'Cat']
2
list=['Tim', 'Sarah', 8, 3 ['Sarah', 8]
'Cat']
4 ['Tim', '8']
print (list[-3:-1])

5
17. What is the output of the 1 1 3 5 7 9
following code snippet? 2 4 6 8
2
i=1
3 1 3 5
while i <=8:
if i%2 == 0: 4 1 3 5 7
i=i+1
continue
print(i,end=' ')
i+=1
18. What is the output of the 1 2
following code? 2.5
2
print("10/4")
3 0
4 10/4
19. What is the output of the 1 5 8 11 14
following code? 5 8
2
for i in (5,8,11,14,17):
3 5 8 11
if i==11:
4 None of the above
break
print(i,end=' ')

6
INF1511/201/2/2018

20. Which of the code snippets will 1 a=1


create an infinite loop? while 1:
print(a)
a+=1
if a==5:
break
2 a=1
while 1:
print(a)
if a>10:
break
3 a=1
while a>=1:
a=a+1
print(a)

4 Option 2 and 3
5 Option 1 and 3

7
Assignment 02 PDF [15]
1. Create a Python program that accepts two numbers as input from the user. The program
should then add the two numbers and print the output. Save the program as sum.py and
add a comment at the beginning of your program. (5)

Provide the following:


i) A screenshot of the sum.py program. Ensure that the screenshots shows your file
name (4).

Marker: 1 Mark for comment in line 1. ½ a mark is rewarded for line 2 & 3 (each). 1
Mark for line 4. 1 Mark for the file name showing correctly in the screenshot.
ii) A screenshot of the output of the program (1).

Marker: 1 mark for screenshot with correct addition.

2. Write a program that prompts the user to enter four integer numbers and then count the odd
and even numbers in the entries. (5)

A sample run:
Enter an integer number: 2
Enter an integer number: 7
Enter an integer number: 4
Enter an integer number: 6
Number of even numbers entered: 3
Number of odd numbers entered: 1

8
INF1511/201/2/2018

cnt_e = 0
cnt_o = 0
for i in range (4):
num = int(input("Enter an integer number: "))
if(num % 2 == 0):
cnt_e += 1
else:
cnt_o += 1
print()
print("Number of even numbers entered:" , cnt_e)
print("Number of odd numbers entered:" , cnt_o)

3. Write a program that repeatedly asks the user to enter a number, either float or integer until
a value -88 is entered. The program should then output the average of the numbers entered
with two decimal places. Please note that -88 should not be counted as it is the value
entered to terminate the loop. (5)

A sample run:
Enter a number(integer or float):5
Enter a number(integer or float):3.2
Enter a number(integer or float):2.1
Enter a number(integer or float):-88
The average of 5 numbers entered is 3.43
#average of numbers entered until -999 is entered as a sentinel value

count = 0
total = 0
num = 0
while(num != -88):
num = float(input("Enter a number(integer or float):"))
if(num != -88):
total = total + num
count = count + 1
avg = total / count
print("The average of %d numbers entered is %.2f" %(count,avg))

OR

#another solution

count = 0
total = 0
num = 0
while(count <= 100):
num = float(input("Enter a number(integer or float):"))
if(num == -88):
break
total = total + num
count = count + 1
avg = total / count
print("The average of %d numbers entered is %.2f" %(count,avg))
9
Assignment 03 MCQ [20]
Question Option Answer
1. … is an example of a mutable 1 Boolean
sequence in Python 2 String
3 Tuple
4 List
5 None of the above
2. The index value of the last element 1 -1
in a list is … 2 0
3 1
4 12
5 z
3. If num is a list variable with five 1 print(num[len(num) - 1])
elements, which print statement 2 print(num[-1])
will output the last element of the
list? 3 print(num[4])
4 All the above
4. What is the output of the following 1 6
code? 2 3
3 2
print(len([(2,4),(6,8),(10, 4 1
12)]))
5 6
5. What is the output of the following 1 sgnimmargorP
code? 2 g-n-i-m-m-a-r-g-o-r-P
3 gnimmargorP
s = "Programming" 4 Programming
r=reversed(s) None of the above
5
for i in r:
print(i, end='')
6. What is the output of the following 1 False
code? 2 True
takeaways 3 KFC
=["KFC","Romans","McDonalds 4 1
"]
print("K" in takeaways)
7. Which of the following statements 1 a=[2*i for i in range(2,6)]
will create and initialise an array a 2 a=[2*i for i in range(4)]
with values 4, 6, 8, 10 3 a=[2*i for i in range(10)]
4 a=[2*i for i in range(4,10)]
8. What is the output of the following 1 [0, 1, 4, 9, 16]
2 [1, 4, 9, 16, 25, 36]
10
INF1511/201/2/2018

Question Option Answer


code? 3 [2, 9, 16, 25, 36, 49]
arr=[i * i for i in range(6)] 4 [0, 1, 4, 9, 16, 25]
print(arr)

9. What is the output of the following 1 Silver


code? 2 Platinum
metal=["Gold", "Silver", 3 1
"Platinum"] 4 3
print(len(metal) - 2)

10. What is the output of the following 1 Gold


code? 2 Platinum
metal =["Gold", "Silver", 3 Silver
"Platinum"] 4 1
print(metal[len(metal) - 2])

11. What is the output of the following 1 Platinum


code? 2 Gold
metal =["Gold", "Silver",
3 Platinum
"Platinum"]
print(metal[len(metal) - 4]) 4 -1
12. What is the output of 1 ['English', 67]
print(marks[2])? 2 ('English', 67)
marks= [("Maths", 75), 3 Science
("Science", 80),
4 English
("English",67)]
13. What is the output of 1 Maths
print(marks[0][0][0])? 2 M
marks= [("Maths", 75), 3 ('Maths', 75)
("Science", 80),
4 None of the above
("English",67)]

14. Which one of the for loops will print 1 for m in months:
elements of the list print(m)
months=["Jan","Feb","Mar"] 2 for i in range(0,len(months)):
one by one? print(months[i])
3 Options 1 and 2

4 None of the above

11
15. Which of the statements will alter 1 days.reverse()
the list 2 days.sort()
3 days.append(['Wed', 'Tue',
days=['Mon', 'Tue', 'Wed']
'Mon'])
to
4 None of the above
days=['Wed', 'Tue', 'Mon']?

16. The function that can be used to 1 dictionary()


create a dictionary is … dict()
2
3 set()

4 None of the above


red
17. What is the output of 1
print(colour.get("red"))? red:1
2
colour={"red":1, "blue":2, 3 None
"green":3}
4 1
red
18. What is the output of 1
print(colour.get(1))? red:1
2
colour={1:"red", 2:"blue", 3 1
3:"green"}
4 None

19. The keyword used to define a 1 return


function in Python is ,,, function
2
3 pass

4 def

20. In the following code, what is 1 argument


message called? parameter
2
def display(message): 3 function header
print(message)
4 function body

12
INF1511/201/2/2018

Assignment 4 PDF [15]


1. Write a program that prompts the user to enter a number between 1 and 5 and prints the
number in words. For instance, if 1 is the input, the output should be One. If the user enters
a different number than 1 to 5 the program should display the message: Entry is out
of range. Provide the code that you used. (4)

# listnumwords.py
words= ['One', 'Two', 'Three', 'Four', 'Five']
n= int(input("Enter a number between 1 and 5: "))
if 1 <= n <= 5:
print ("The word is", words[n-1])
else:
print ("Entry is out of range")

2. Write a program that asks the user to enter a sentence and a specific letter to be replaced
with the the % character. If the letter entered does not appear in the sentence, print an
appropriate message. (6)
Hint:- refer to built-in functions for strings.
Sample runs:
(1)
Enter a sentence: I am glad you could make it!
Enter a letter: a
I %m gl%d you could m%ke it!
(2)
Enter a sentence: How are you?
Enter a letter: b
The character does not occur in the sentence.

#string-replace
count_l = 0;
sen = input("Enter a sentence: ")
let = input("Enter a letter: ")
for letter in sen:
if(letter == let):
count_l += 1
if(count_l == 0):
print("The letter does not occur in the sentence.")
else:
sen1 = sen.replace(let, '%', count_l)
print(sen1)

13
3. Write a program that uses a recursive function named printFactors() to print all the
factors of an integer number received from the main program. (5)

A sample run:
Enter an integer number: 12
The factors of 12 are :
1
2
3
4
6
12

#recursion - print factors of a number


def printFactors(n, f=1):
if (f >= n):
print(f)
return f #this line is important to stop recursive call
if (n % f == 0):
print(f)
printFactors(n, f + 1)
num = int(input("Enter an integer number: "))
print("The factors of %d are :" %(num))
printFactors(num)

14
INF1511/201/2/2018

Assignment 5 MCQ [20]


Question Option Answer
1. From the following code identify the line 1 obj=Num()
of code that invokes the __getattr__
method. 2 print(obj.x)
class Num(object): 3 obj.y=20
def __getattr__(self, name):
return 10
4 print(obj.y)
def __setattr__(self,name,value):
self.__dict__[name]=value
obj = Num() 5 Both 2 and 4
print(obj.x)
obj.y = 20
print(obj.y)

2. From the following code identify the line 1 obj=Num()


of code that invokes the __setattr__
method.
2 print(obj.x)
class Num(object):
def __getattr__(self, name):
return 10 3 obj.y=20
def __setattr__(self,name,value):
self.__dict__[name]=value
4 print(obj.y)
obj=Num()
print(obj.x)
obj.y=20 5 Both 2 and 4
print(obj.y)
3. A … variable is shared by all instances of 1 class
a class.
2 object
3 data
4 instance
4. … is a special method that is 1 __str__
automatically invoked right after a new
2 __init__
instance of a class is created.
3 print
4 None of the above
5. Which is true in Python? 1 If any of the methods
__get__, __set__ or
__delete__ is implemented
by a class, it can be
called a descriptor.
2 In multiple inheritance
the base classes cannot
have a method with the
same name.

15
Question Option Answer
3 Python does not support
polymorphism.
4 None of the above
6. In Python, all classes automatically 1 base
extend the built-in … class, which is the
2 self
most general class possible.
3 object
4 None of the above
7. Which file access mode option allows file 1 r+
reading only?
2 r
3 read+
4 read
8. Assuming that a text file file.txt exists 1 f=open('file.txt', r)
with few lines of text, which of the code line=f.read()
snippets will read the entire file?
2 f=open('file.txt', 'r')
line=f.read(1)
3 f=open('file.txt', 'r')
line=f.read(-1)
4 None of the above

9. In the following code fragment identify the 1 b = Book()


line of code that raises the
AttributeError exception? 2 print(b.price)
class Book(object):
title = "Python Programming" 3 b.disp_details()
author = "Kenneth Lambert"
def disp_details(self):
print(self.title,self.author) 4 None of the above
b = Book()
print(b.price)
b.disp_details()
10. The … statement is used to place an 1 except
error-checking statement in a Python
program.
2 assert

3 finally
4 None of the above

16
INF1511/201/2/2018

11. Which file access mode option opens a 1 a


file for reading and appends contents to
the end of the file? 2 r+

3 a+

4 A

12. To write a string to a file, the … method 1 open()


can be used.
2 close()
3 write()
4 None of the above
13. Which of the statements will open the text 1 f=open('abc.txt')
file abc.txt for reading only?
2 f=open('abc.txt', 'r')
3 f=open('abc.txt', 'r+')
4 All the above
5 Only 1 and 2
14. Which method writes a list of strings to a 1 write()
text file?
2 writelines()
3 writefile()
4 None of the above
15. What will be the content of file xyz.txt 1 OneTwoThree
after the following code has been 2 One
executed?
Two
f = open("xyz.txt", "w+") three
lst=['One','Two','Three']
3 One Two Three
f.writelines(lst)
f.close() 4 None of the above
16. If f is a file handler returned by the 1 f.seek(0)
open() method on a text file, which 2 f.seek(0,1)
statement can be used to move the file
handler to the end of the file? 3 f.seek(0,2)
4 None of the above

17
17. If first.txt exists with few lines of text 1 f=open("first.txt", 'r+')
in it which of the given code snippets will for line in f:
read the file and output the lines of text print(line, end = '')
f.close()
one by one to the console?
2 import sys
f=open("first.txt", 'r+')
for line in f:
sys.stdout.write(line)
f.close()
3 f=open("first.txt", 'w+')
lines=f.readlines()
for i in range(0,
len(lines)):

sys.stdout.write(lines[i])
f.close()
4 Option 1 and 2.
18. … is the process of converting structured 1 Pickling
data in Python to data stream format.
2 Unpickling
3 Deserialization

4 None of the above


19. A module that can be used for 1 sys
serialization in Python is …
2 pickle
3 stdout
4 None of the above
20. The … function of the pickle module can 1 load()
be used to serialize a serializable data
2 pickle()
structure in Python and save it into an
open file. 3 dump()
4 write()

18
INF1511/201/2/2018

Assignment 6 PDF [20]


1. Write a program that accesses and prints line 2 of the classlist.txt file. (2)

import linecache
line=linecache.getline('classlist.txt', 2)
print ('The content of the third line is:', line)

2. Create a class Publication with public member variables publisher, title and
price with the following specifications: (18)
• Add init() method of the class that initialises string member variables to empty strings
and numeric values to 0.
• Add two more methods to the class: populate() and display().
o The populate() method is used to assign values to the member variables of the
class.
o The display() method is used to display the member variables of the class.
• Derive a class Book from Publication.
o The class Book has two public member variables of its own: ISBN and
authorname.
o Define the init() method for the class Book that initialises string member
variables to empty strings and numeric values to 0, and also override the
populate() and display() methods of the base class.
o Create an instance bookObj of the class Book in a main program.
• The main program should then prompt the user to enter the following values:
Publisher : Romfort
Title : Computing for beginners
Price: 280
ISBN: 123456
Author Name: Jo Mahlangu
• The above attributes should be assigned to the instance bookObj using its
populate() method.
o Then display all these attributes back to the console using the display() method
of the instance bookObj.

A sample run:
Enter publisher name: Romfort
Enter title: Computing for beginners
Enter price: 280
Enter ISBN number: 123456
Enter author name: Jo Mahlangu

The details of the book are:


Publisher: Romfort
Title: Computing for beginners
Price: R280.00
ISBN: 123456
Author Name: Jo Mahlangu

19
#single inheritance - class Publication
class Publication(object):

def __init__(self):
self.publisher = ""
self.title = ""
self.price = 0.0
def populate(self, pub,t,pr):
self.publisher = pub
self.title = t
self.price = pr
def display(self):
print("Publisher:", self.publisher)
print("Title:", self.title)
print("Price: R%.2f " %(self.price))

class Book(Publication):
def __init__(self):
Publication.__init__(self)
self.ISBN = 0
self.authorname = ""

def populate(self, pb,t, pr, isbnNo,auth):


Publication.populate(self,pb,t,pr) #self parameter is required
self.ISBN = isbnNo
self.authorname = auth

def display(self):
Publication.display(self) #self parameter is required
print("ISBN:", self.ISBN)
print("Author Name:", self.authorname)

#main program
bookObj = Book()
pb = input("Enter publisher name: ")
t = input("Enter title: ")
pr = float(input("Enter price: "))
iNo = int(input("Enter ISBN number: "))
a = input("Enter author name: ")

bookObj.populate(pb,t,pr,iNo,a)
print()
print("The details of the book are:")
bookObj.display()

20
INF1511/201/2/2018

Assignment 7 PDF [15]


Create an application using PyQt that reads a string and a character from the user and count
the number of occurrences of the character in the string. The count should be case-insensitive.
In other words, if ‘i’ is entered as the character then both capital letter ‘I’ and small letter ‘i’ in the
string should be counted (see sample output given below). The application interface should look
similar to the example provided, please use the assignment rubric as guidance.

21
Assignment Evaluation Rubric

Requirement No Partial Meets Exceed


(must be submitted) attempt attempt expectation expectation
1 Copy & Paste a print 0 0 2 N/A
screen of the program
user interface(UI) in
design time.
2 Copy & Paste a print 0 1 2 3
screen of the object
inspector listing all the All components
widgets in your must be
application. Must include named.
all the components on the
user interface.
3 Copy and Paste a print 0 0 2 3
screen of the program UI
in run time showing the Should use a
number of occurrences of Group Box in
a character in a string. the interface

4 Copy & Paste the 0 2 4 7


complete code of the
source file which invokes Number of Must include
your UI design. occurrences comments.
of a
character Have proper
should be checks in place
displayed to make sure
correctly. that the
The count program does
should be not crash if the
case pushbutton
insensitive. ‘Count the
characters’ is
clicked without
a string or a
character or
both not
entered.

22
INF1511/201/2/2018

Requirement Solution
(must be submitted)
1 Copy & Paste a print
screen of the program
user interface(UI) in
design time.

2 Copy & Paste a print


screen of the object
inspector listing all the
widgets in your
application. Must
include all the
components on the
user interface.

3 Copy and Paste a print


screen of the program
UI in run time showing
the number of
occurrences of a
character in a string.

4 Copy & Paste the See the code for .pyw file below.
complete code of the
source file which
invokes your UI design.

23
Item 4

#callcountchar.pyw
import sys
from countchar import *

class MyForm(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_DlgCountchar()
self.ui.setupUi(self)
#the following line will call occur() when btnCount is clicked
self.ui.btnCount.clicked.connect(self.occur)

def occur(self):
#we should add validation to check if the edit box is empty.otherwise python will throw error
l = len(self.ui.edtString.text())
if l != 0:
if len(self.ui.edtChar.text()) != 0:
line = self.ui.edtString.text()
ch = self.ui.edtChar.text()
numChar = 0
for i in range(0,l):
if(line[i].lower() == ch.lower()): #for case-insensitive count
numChar += 1
self.ui.lblOccur.setText("Number of occurences: " + str(numChar))

if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = MyForm()
myapp.show()
sys.exit(app.exec_())
24
INF1511/201/2/2018

Assignment 8 PDF [15]


Create the following by using Qt Designer, which aims to benefit a local hospital. The program
should be able to add the patient’s name, age, gender and the ward he or she is admitted to
and delete individual patient entries as well as the entire list of entries. Please make use of the
assignment rubric provided below.

25
Assignment Evaluation Rubric

Requirement No Partial Meets Exceed


(must be submitted) attempt attempt expectation expectation
1 Copy & Paste a print 0 0 2 N/A
screen of the program
user interface(UI) in
design time.
2 Copy & Paste a print 0 1 2 3
screen of the object
inspector listing all the All components
widgets in your must be
application. Must include named.
all the components on the
user interface.
3 Copy and Paste a print 0 0 2 3
screen of the program UI
in run time showing at
least 3 patient entries.
4 Copy & Paste the 0 2 5 7
complete code of the
source file which invokes Code Must include
your UI design. provided comments
that invokes
buttons in
user
interface.

Assignment Evaluation Rubric

Requirement Solution
(must be submitted)
1 Copy & Paste a print
screen of the program
user interface(UI) in
design time.

26
INF1511/201/2/2018

2 Copy & Paste a print


screen of the object
inspector listing all the
widgets in your
application. Must include
all the components on the
user interface.

3 Copy and Paste a print


screen of the program UI
in run time showing at
least 3 patient entries.

4 Copy & Paste the Please see below.


complete code of the
source file which invokes
your UI design.
Point 4:

# calllist.pyw
import sys
from hospital import *
from PyQt4.QtGui import *

27
class MyForm(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_DlgHospital()
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.btnAdd,
QtCore.SIGNAL('clicked()'), self.addlist)
QtCore.QObject.connect(self.ui.btnDelete,
QtCore.SIGNAL('clicked()'), self.delitem)
QtCore.QObject.connect(self.ui.btnDeleteAll,
QtCore.SIGNAL('clicked()'), self.delallitems)

#code that invokes the Add button


def addlist(self):
if self.ui.chb_18.isChecked()==True:
result1="<18 years"
if self.ui.chb_18to33.isChecked()==True:
result1="between 18 and 33 years"
if self.ui.chb_33.isChecked()==True:
result1=">33 years"
if self.ui.chb_Male.isChecked()==True:
result2="Male"
if self.ui.chb_Female.isChecked()==True:
result2="Female"
if self.ui.chb_General.isChecked()==True:
result3="General ward"
if self.ui.chb_ICU.isChecked()==True:
result3="ICU ward"
if self.ui.chb_Pediatric.isChecked()==True:
result3="Pediatric ward"
self.ui.lstPatients.addItem(self.ui.edtName.text()+ ' '
+ str(result1)+ ' ' + str(result2)+ ' ' + str(result3))
self.ui.edtName.setText('')
self.ui.edtName.setFocus()

#code that invokes the Delete button


def delitem(self):

self.ui.lstPatients.takeItem(self.ui.lstPatients.currentRow())

#code that invokes the DeleteAll button


def delallitems(self):
self.ui.lstPatients.clear()

if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = MyForm()
myapp.show()
sys.exit(app.exec_())

© 2018 Unisa

28

You might also like