Nothing Special   »   [go: up one dir, main page]

Logbook 1 and 2

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 16

Introduction to

Software
Development
CP30681E CP3CS81E

Logbook

STUDENT NAME
STUDENT NUMBER
Table of Contents

Reflective Portfolio 3
Seminar week 1 4
Task Describe the different “layers” of Software that exist on a typical
computer and explain why there are different layers of software. 4
Task 1.2: Describe what an algorithm is and explain why it is a useful
“tool” to translate from a human level problem to a computer program.4
Task 1.3: Enter the following expressions in the Python IDLE and note
down the response to each. Do they differ from what you would
expect? 4
Seminar week 2 5
Task 2.1: Write an algorithm that describes how to make scrambled
eggs, try to use control words, like IF, WHEN, UNTIL, WHILE, WAIT,
AND, OR. 5
Task 2.2: List at least three advantages and disadvantages of an
interpreter and a compiler 5
Task 2.3: Is IDLE (the Python language shell) an Interpreter or a
Compiler? Explain your answer. 5
Task 2.4: Write a command in the IDLE shell that says “Hello world” 5
Task 2.5: Write a program that produces the following output: 5
Seminar week 3 6
Seminar week 4 7
Seminar week 5 8

Reflective Portfolio

Write a one page reflective portfolio for the first 5 weeks of the module.
Be critical and thorough. This is an opportunity for you to write what you
learnt, the benefits, the things you liked in these 5 weeks. In addition, do
not hesitate to state the challenges you faced, which includes things that
did not go right. Finally, avoid blaming others and be professional with
your writing.
2
Introduction to Software Development
Seminar week 1

Task Describe the different “layers” of Software that exist on a typical


computer and explain why there are different layers of software.

Task 1.2: Describe what an algorithm is and explain why it is a useful


“tool” to translate from a human level problem to a computer program.

Task 1.3: Enter the following expressions in the Python IDLE and note
down the response to each. Do they differ from what you would expect
Seminar week 2

Task 2.1: Write an algorithm that describes how to make scrambled


eggs, try to use control words, like IF, WHEN, UNTIL, WHILE, WAIT,
AND, OR.

Task 2.2: List at least three advantages and disadvantages of an


interpreter and a compiler

Task 2.3: Is IDLE (the Python language shell) an Interpreter or a


Compiler? Explain your answer.

Task 2.4: Write a command in the IDLE shell that says “Hello world”

Task 2.5: Write a program that produces the following output:


● Hello World
● I am in my ISD class right now

Seminar week 3
Introduction to Software Development (ISD) Seminar week 3 Tasks: 1.

3
Introduction to Software Development
Write a Python program that introduces yourself following the same
pattern as below
2. Write a program that asks for two numbers, adds them up and
displays the result.
3. What do the following lines of code output? Why do they give a
different answer? ∙ print(2 / 3) ∙ print(2 // 3)
4.Write a Python program which accepts the user's first and last name
and print them in reverse order ( i.e. last name followed by first name
with a space between them)
5. Write a Python program that will accept the base and height of a
triangle and compute the area (Formula: base*height/2)

Introduction to Software Development (ISD)

Seminar week 4
Tasks:

1. Explain the mistake in the following code:


radius = input("Radius: ")
x = 3.14
pi = x
area = pi * radius ** 2
Problem: Data type mismatch
Solution:
>>> radius = float(input("Radius: "))
>>> x = 3.142
>>> pi = x
>>> area = pi * radius ** 2

4
Introduction to Software Development
>>> print(area)
12.568
2. Consider the following code:
x = 19.93
y = 20.00
z=y–x
print(z)
Improve the code so that the output is only two decimal places.
Solution:
>>> x = 19.93
>>> y = 20.00
>>> z = y – x
>>>print(round(z, 2))
0.07

3. Write a python code that takes a decimal number as input


and round off the number as follows (Hint: Use math
module)
For example:
Enter number = 4.6
Round off to 4, and
Round off to 5
Solution:
>>> import math
>>> x = float(input("enter number: "))
>>> print(floor(4.6))
4
>>> print(ceil(4.6))
5

5
Introduction to Software Development
4. Write a Python program to print the calendar of a given
month and year.
(Hint: Use 'calendar' module)
Solution:
import calendar
y = int(input("Input the year : "))
m = int(input("Input the month : "))
print(calendar.month(y, m))

5. Write a python program that prints the balance of an


account after the first, second, third and fourth year. The
account has an initial balance of £1,000 and earns 5 per
cent interest per year.
Solution:
>>> initial = 1000
>>> firstYear = initial * 1.05
>>> secondYear = firstYear * 1.05
>>> thirdYear = secondYear * 1.05
>>> print(firstYear……………)

6. Write a python code to create a window, display a


welcome message “Welcome to Python” and has a button
“Click here”. Add foreground and background colours to it.
In addition, provide comments next to each line of code
explaining the purpose of the line of code (Hint: Use
tkinter module)

Solution:
>>> from tkinter import *
>>> screen = Tk() # this will create a new window, which
will pop up
>>> screen.title("hello") # this will caption the window
>>> welcome_message = Label(text = "welcome to my
first window", fg = "red", bg = "blue") # this will display a
6
Introduction to Software Development
welcome message on the window with foreground and
background colours
>>> welcome_message.pack()
>>> click_here = Button(text = "submit", fg = "red", bg =
"yellow") # this will create a button
>>> click_here.pack() # pack mean place the button in the middle.
You can use your own coordinates as well.

Introduction to Software Development (ISD) Seminar Week 5


Tasks: 1. Which of the following conditions are True or False, if a =
13 and b = 14? a) a + 1 <= b b) a + 1 >= b c) a + 1 != b
2. What is the error(s) in the following code? Correct the code and
provide a screenshot of the corrected code. scoreA = 10 scoreB =
10 if scoreA = scoreB : print("Tie")
3. Write a program that asks the user for an integer number and
then prints out whether the entered number is “Divisible by 7” or
“Not divisible by 7”
4. Supply a condition in this if statement to test if the user entered
a “Y” or “y”: userInput = input("Enter Y to quit.") if . . . #supply
statement print("Goodbye") #if the user entered “Y” or “y”.
5. Using the flow chart below, construct the if, elif, else control
structure necessary to implement the flow chart. Complete your
program to describe the earthquake by asking the user to enter a
magnitude on the Richter scale and print out the effect that
magnitude would have had
Introduction to Software Development Seminar Week 6
Create a word document and answer the following questions. Where
there is coding involved, take a screenshot of the code along with the
output and attach it to the word document below each question.
Tasks: 1. Write a python program using string manipulations. The
program should take three strings from the user (p, q and r) and display

7
Introduction to Software Development
the following: • Concatenation (p+q+r) in capital letters • Concatenation
of (r + p) in lowercase • total number of characters within (p+q+r)
2. Write python program to allow the user to input his/her age. Then the
program will show if the person is an infant, child, a teenager or an adult.
3. Write a python program to compute body mass index (BMI). The
program should take input values such as weight and height in order to
calculate BMI and display it on the screen. In addition, the program
should display to the user whether the calculated BMI result corresponds
to underweight, healthy weight or overweight. Formula: weight (kg) /
[height (m)]2

Introduction to Software Development Seminar Week 7


Create a word document and answer the following questions. Where
there is coding involved, take a screenshot of the code along with the
output and attach it to the word document below each question.
Tasks: 1. Create a while loop that prints out all the squared numbers
from 1 to 10 (e.g. 1, 4, 9, 16, ... , 100).
2. Create a while loop which would print the numbers from 1 to 15,
skipping numbers 3, 5, and 7 from the printed numbers. Hint: Use
Continue.
3. Write a program that sets a password as “changeme” and asks the
user to enter the password and keeps asking until the correct password
is entered and then says “Password Accepted”. The program should
also count how many attempts the user have made and tell them after
the password has been accepted.
4. Modify task 1 such that, if the user takes more than 5 attempts the
program should say, “Access denied. Please contact IT services to reset
your password”.
Introduction to Software Development Seminar Week 8
Create a word document and answer the following questions. Where
there is coding involved, take a screenshot of the code along with the
output and attach it to the word document below each question.

8
Introduction to Software Development
Introduction to Software Development Seminar Week 8
Tasks: 1. Consider the following function: def mystery (x, y): result = (x +
y) / (y - x) return result What is the result of the call mystery (2, 3)? 2.
What does this program print? def main(): a = 5 b = 7 print(mystery(a, b))
def mystery(x, y): z = x + y z = z / 2.0 return z main()
3. What does this program print? def main(): a = 4 print(mystery(a + 1))
def mystery(x): y = x * x return y main()

Introduction to Software Development Seminar Week 9


Create a word document and answer the following questions. Where
there is coding involved, take a screenshot of the code along with the
output and attach it to the word document below each question.
Tasks: 1. Write a Python program that prompts the user to enter three
numbers. Write three functions as follows, then call each function,
passing the numbers the user entered as argument values, and print the
results: ∙ The first function should take three numbers as arguments and
return the sum of the numbers ∙ The second function should take three
numbers as arguments and return the smallest of the numbers ∙ The
third function should take one number as an argument and return the
square of the number – call this function three times, once for each
number the user entered 2.
Demonstrate the use of functions in the BMI calculator created in
seminar activity (week 6).
3. Write a Python program using a function to loop a message. The
program should prompt the user to enter a message and its count. The
message and count should be passed as arguments to the function.
After calling the function, the program should display the typed message
the specified number of times.
4. Swap the numbers: Write a Python program using a function to swap
two numbers. The program should prompt the user to enter two numbers
and store these numbers in global variables. After calling the swap
function, the numbers in the global variables should be swapped, and
the program should then display them on the screen. Expected output:

9
Introduction to Software Development
5. Write a Python function to check whether a year (integer) entered by
the user is a leap year or not. Expected Output: Input a year: 2017 False

Introduction to Software Development Seminar Week 10


Create a word document and answer the following questions. Where
there is coding involved, take a screenshot of the code along with the
output and attach it to the word document below each question. Note:
This week’s seminar activity will test your understanding of the python
programming paradigms that you have learnt so far (Week 1 – Week
10), which should be reflected in the task given below: Task: Write a
python program to simulate an online store. The program should begin
by displaying a list of products and their prices. There should be a
minimum of 4 products offered. The program should ask the user to
choose a product and then ask the user to enter the quantity they
require of that product. The program should then allow the user to keep
choosing more products and quantities until they enter something to
indicate they want to end the program (e.g. a given number or ‘q’ or

10
Introduction to Software Development
‘exit’). The program should then tell the user the total amount for the
products they have selected
Introduction to Software Development Seminar Week 11
Create a word document and answer the following questions. Where
there is coding involved, take a screenshot of the code along with the
output and attach it to the word document below each question.
Tasks: 1. a) Copy and paste the following code into your Python editor.
Check that the code runs and produces the output you expect. class
Student: def init (self, name, age, course, ID): self.name = name self.age
= age self.course = course self.ID = ID def print_details(self):
print("Name: " + self.name) print("Age: " + str(self.age)) print("Course: "
+ self.course) print("Student ID: " + self.ID) student1 = Student("Bob",
20, "Computer Science", "1000121") student2 = Student("Alice", 21,
"Computer Science", "1000475") student3 = Student("Jane", 18,
"Information Technology", "1000823") student1.print_details()
student2.print_details() student3.print_details() b)
At the end of the file, add code to prompt the user to enter detailsfor a
new student. Using these details, create a new object of class Student,
and call the print_details function to display the details of the new
student.Page 2 of 3 Example output: 2. a)

11
Introduction to Software Development
In a new Python program, copy and paste the following code: class
BankAccount: def init (self, account_number, balance):
self.account_number = account_number self.balance = balance def
print_balance(self): print("Account balance for account " +
self.account_number + " is: " + str(self.balance)) account1 =
BankAccount("123456789", 1000.00) account1.print_balance()

Check that the code runs and produces the output you expect. Create
two more BankAccount objects and call the print_balance function to
display the balance of these accounts. Example output: b)

Add another attribute to the BankAccount class, to store the name of the
account holder. Modify the constructor function as necessary, and
modify the print_balance function so that it also prints out the account
holder’s name. Add a new function to the class, called print_name, which
prints the account number and the name of the account holder. At the
end of the program, call this function on the objects you have created, to
12
Introduction to Software Development
show the names of the account holders. Example output:Page 3 of 3 c)
Add two new functions to the BankAccount class, one called withdraw
and one called deposit. The withdraw function should take one
parameter, and should deduct the amount passed in the parameter from
the account balance. The deposit function should also take one
parameter, and should add the amount passed in the parameter to the
account balance. At the end of your program, call both functions on the
objects you have created. Then call the print_balance function to sh

Introduction to Software Development Seminar Week 12


Create a word document and answerthe following questions. Where
there is
codinginvolved,takeascreenshotofthecodealongwiththeoutputand attach
itto the word document below each question.
Thisweek’sseminarrequiresyoutouseinheritance:youwillbecreatinga
parent class called Product,to represent a product on the Amazon
website, andachildclasscalledBook,whichinheritsfromProduct.
Tasks: 1. Create a Python class called Product, to represent a product
on the Amazon website. Your class should have five data fields: A
variable self.product_id to store the product ID A variable self.price to

13
Introduction to Software Development
store the price of the product A variable self.prime_eligible, which can
have a value of either True or False to indicate whether or not the
product is eligible for Amazon Prime A variable self.number_in_stock to
store the number of this product currently in stock A variable
self.date_added to store the date when the product was added to the
Amazon website
2. Write the following functions for your Product class: a. A constructor
function ( init ) b. Setter and getter functions for each of the data fields in
the Product class c. A print() function which prints the values of all the
data fields.
3. Next, define a new class, called Book, which inherits from the Product
class. The Book class should have the following five data fields in
addition to the ones it inherits from the Product class: A variable self.title
to store the book titlePage 2 of 2 A variable self.author to store the name
of the book’s author A variable self.num_pages, to store the number of
pages in the book A variable self.publisher to store the name of the
publisher A variable self.publication_date to store the date when the
book was published.
4. Write the following functions for the Book class: a. A constructor
function ( init ) - this should call the constructor function of the parent
class, and then set the additional five data fields of the Book class b.
Setter and getter functions for each of the five new data fields in the
Book class c. A print() function which prints the values of all the data
fields – this should call the print() function of the parent class, and then
also print the remaining data fields that belong to the Book class
5. Look on Amazon for three different books. Using the information on
the Amazon website, create three objects of class Book in your code.
Test your code by calling the print() function and getter and setter
methods on the three Book objects you have created

Introduction to Software Development Seminar Week 13


Create a word document and answer the following questions. Where
there is coding involved, take a screenshot of the code along with the
output and attach it to the word document below each question.

14
Introduction to Software Development
15
Introduction to Software Development
16
Introduction to Software Development

You might also like