0% found this document useful (0 votes)
2 views2 pages

Python Homework 4

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

Python Homework 4

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

Homework 4 Writing algorithms

Introduction to Python

Homework 4: Writing algorithms


1. State for each question, whether the statements are True or False, and give the reason
why.

False, because it’s used as


a. Pseudocode is a programming language a planning tool that’s half
for non-programmers English and half Code for
programmers.

b. READ and INPUT are interchangeable


True because they do the
terms in pseudocode for getting data into
same action.
a program

c. A logic error wil be found when the False because there will be
program is compiled. an error with the program.

False because the program


can still run but with
d. Logic errors are the easiest type of
embedded flaws that aren’t
errors to fix in a program.
always noticed by the
creator.

e. This code will generate a run time error:


True, when running the code
total = 10
it says “divide by zero
total = total/0
error”.
print(total)

[10]
2. Write pseudocode for a program which will ask a user to enter two numbers a and b.
It then asks what operation is to be performed: a*b, a/b, a//b or a%b, performs the
appropriate calculation and prints out the result.

If the user does not enter a valid response, print an error message. [10]

Total 20 marks

1
Homework 4 Writing algorithms
Introduction to Python

input two numbers


input the operation to be performed in characters
if operation = multiply
result = a*b

else if operation = divide


result = a /b

else if operation = integer division (floor division)


result = a//b

else if operation = find remainder


result =a % b

else
result = “Error – invalid operation entered”
endif
print result

You might also like