Structured Programming (Python) Lecture
notes
Roles of hardware & software in a computing
system
Hardware vs software
o Set of instructions given to a computer program
(software)
o Computer hardware is what executes the instructions
(hardware)
E.g. Input devices (keyboards), CPU, Main
memory, Output devices, second memory
Types of programming languages
Low-Level or machine languages
o Binary
Assembly language
o Uses mnemonics instead of 0s and 1s
o E.g. Cobalt
High Level computer languages
o Understood by humans
Compiler vs Interpretor
Software Development Thinking
Analyze the problem
o Identify what problem to solve
Determine specifications
o What program must do
Create a design
o What steps can solve- the algorithm
Software Development Methodology
Implement the design
o The steps in programming language
Test/Debug/Run the program
Maintain the program
Python programming fundamentals
def main():
print(“Hello world”)
print(“Hello world”)
print(2+3)
print(“2+3=”, 2+3)
Output:
Hello world
5
2+3 = 5
print(“Hello world”, end = “”)
print(2+3, end=“”)
print(“2+3=”, 2+3)
Output:
Hello world 5 2+3 = 5
#comment
Variable -> A name given to a value
o Assignment statement:
o var = value
birthyear = 2000
age = 2019 – birthyear
o Simultaneous Assignment Statement:
o Var1, …., Varn = value1, ….., valuen
x, y = 5, 2
sum, diff = x+y, x-y
Input Statement
o input (prompt) All user inputs are of str type
name = input(“Enter friend’s name: ” )
print(“Hello”, name)
Output:
Enter friend’s name: Alan
Hello Alan
Input Statement
o input (prompt) All user inputs are of str type
name = input(“Enter friend’s name: ” )
print(“Hello”, name)
Number data types
o int
whole number, exact
o float
decimal number, imprecise
Type conversion
o score = int(input(“Enter score:”))
weight = float(input(“Enter weight:”))