Python Programming
Python Programming
Translation Program
● Compiler: A compiler is a special program that translates a programming language's
source code into machine code, bytecode or another programming language.
● Interpreter: An interpreter is a program that directly executes the instructions in a
high-level language, without converting it into machine code
● Translator: a program. that converts source code into object code.
● Source code (natural language of the programmer)
● Object code (converted source code)
Source code is the natural language that the program is written in.
Codes are created in the editor and executed in the shell.
Information Technology
Introduction to Python Programming
Errors
Syntax Errors are mistakes in the source code, such as spelling and punctuation
errors, incorrect labels, and so on, which cause an error message to be generated by
the compiler. Does not conform to the programming language. Syntax Error will
prevent the source code from converting to object code.
Logic Error is a bug in a program that causes it to operate incorrectly, but does not
prevent the program from compiling. A logic error produces unintended or
undesired/unexpected output (result) or other behaviour, although it may not
immediately be recognized as such.
Objectives:
1. Use comments
2. Set up variables
3. Take input from user
4. Use different data types in Python
Comments
Comments start with a number sign followed by natural language.
To explain a block of statements or single line of statements in a program.
Comments are placed above or beside the line of statements that they are describing.
Information Technology
Introduction to Python Programming
In python
display=print.
10100
Pseudocode total
\\to accept 3 numbers, calculate the sum, display the sum
Declaration \\declaration of identifier
Variables
Num1, num2, num3, tot ← integer
Start
Display “Enter number” \\request for first number
Read num 1
Display “Enter next number” \\request for 2nd number
Read num 2
Tot ← num 1+num2+num3 \\calculating total
Display total
Python Codes
#this program will accept 3 numbers, calculate the total, display the total.
total = 0 #total is assigned a nominal value
num1=int(input("Please enter first number"))
num2=int(input("Enter your second number"))
num3=int(input("Enter your third number")) #calculating total for the 3 numbers
total =num1+num2+num3
print (total)
Information Technology
Introduction to Python Programming
In python for
equality ==
Assignment =
Comment #
Not equal !=