0% found this document useful (0 votes)
4 views

Programming Grade 7 (2)

This document provides an overview of programming and system development, focusing on computer programming languages, including machine language, assembly language, and high-level languages like Python. It explains the concepts of syntax and semantics, the use of the Python programming language, and introduces variables, data types, and basic programming functions. Additionally, it includes practical exercises for using Python's IDLE environment to write and execute code.

Uploaded by

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

Programming Grade 7 (2)

This document provides an overview of programming and system development, focusing on computer programming languages, including machine language, assembly language, and high-level languages like Python. It explains the concepts of syntax and semantics, the use of the Python programming language, and introduces variables, data types, and basic programming functions. Additionally, it includes practical exercises for using Python's IDLE environment to write and execute code.

Uploaded by

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

April-28-2025

UNIT-7.3
Programming and system
development
A computer program is a set of instructions that
commands a computer what to do.
Computers do whatever task they do by simply following
the instructions stated
in programs. This unit covers topics related to computer
programs including
programming languages, syntax, and semantics. The high-
level programming
language known as Python is used to demonstrate the
basic concepts of
programming.
Types of Programming Languages
Brainstorming
1. How do computers do the types of tasks we observe
them doing?
Programming languages: are computer languages that
are used to write different types of computer programs.
❖ They are generally grouped into machine language,
assembly language, and high-level language.
A. Machine Language
• Machine language is a low-level computer language. It is
a language in which everything including instructions,
numbers, and memory locations are represented in 1s
and 0s – binary system.

Machine language is the language that computers


understand directly without any need for translation. That
is why it is very fast and uses memory efficiently. However,
writing programs in machine language is very difficult.
B.Assembly Language
Assembly language is also a low-level computer
language but, instead of 1s and 0s, it uses symbols
known as mnemonics. Though it is easier than using a
binary system, assembly language is still difficult.
Since computers do not directly understand any
program outside the machine language, programs that
are written in assembly language require a special type
of software. This software is known as Assembler, and it
is used to translate assembly language instructions into
machine language.
C.High-Level Language
High-level languages are closer to human
languages compared to both assembly and
machine languages.
This type of language allows programmers to
focus more on the problem they want to solve
than on the programming language.
Examples of high-level programming languages
include C, C++, Java, C#, Python, Perl, and Ruby.
Just like assembly language programs, high-level language
programs also cannot be directly executed by the
computer.
The programs have to be first translated into a machine
language using translator software.
Depending on the programming language, the translator
software can be either a Compiler or an Interpreter.
Compilers translate high-level language written programs
all at once into machine language .
The machine language is then executed by the
computer. Examples of programming languages
that use compilers are C, C++, Java, and C#.
Interpreters, on the other hand, translate and
execute programs a statement at a time.
They don’t translate the whole program together
as do compilers.
Examples of programming languages that use
interpreters include Python, Perl, and Ruby.
Syntax and Semantics
Like any human language, all programming languages have
syntax and semantics.
Syntax refers to the rules of the programming language.
It defines the structure or grammar of the language that
programs should strictly follow.
Semantics of a programming language, on the other
hand, is related to the meaning of elements of
a program and what they do.
A program must be written with the correct syntax
dictated by the programming language for the
program to be executed by the computer.
If a program violates any of the syntax rules of a
language, the compiler or the interpreter
produces an error message. Such type of error is
known as a syntax error.
A program can have no syntax error and get
executed properly but can still behave in a way
different from what it is intended to.
This kind of error is known as logic error and is
associated with the semantics of a language.
Since compilers or interpreters do not catch logic
errors, they are far more difficult to identify and
fix than syntax errors.
Basics of Python
Python is one of the popular high-level programming
languages in use today.
It is widely considered a much easier language to learn.
This is one of the main reasons why it is a widely chosen
language for teaching programming to those who are new
to programming .
Python has a free integrated development environment
known as IDLE.
IDLE stands for Integrated Development and Learning
Environment.
To write Python codes, the interactive interpreter or
the text editor of the IDLE can be used.
The interactive interpreter is used to write one line of
Python code at a time and is less convenient to write
and execute a large number of codes.
Using the text editor, however, any number of codes
can be written and get executed with a single
command.
Using the Interactive Interpreter
The Interactive Interpreter contains a Python
shell, which is a textual user interface used to
work with the Python language.
The Interactive Interpreter is displayed
when the IDLE is opened.

Figure shows the Interactive Interpreter.


The >>> is where codes are written and is called the
prompt. After a user writes a code and presses the
enter key, the prompt (>>>) reappears for the user to
write the next code.
The following example demonstrates what the
Interactive Interpreter does when the enter key is
pressed after a simple expression is written.

>>>5+6
11
>>>
5+6 is a syntactically valid expression that evaluates to
11.
Therefore, the Python interpreter evaluated the
expression and displayed 11.
If, for example, a syntactically invalid expression like 5+ is
given, the interpreter generates the following syntax
error:
To display something on the screen, the print() function
is used in Python.
The following example shows how a string is displayed
using the print() function.
>>>print("Hello World")
Hello World
>>>
Note that the IDLE uses different types of colors for the
different elements of a Python code to make them easily
distinguishable.

By default, outputs are displayed in blue color; functions


are displayed in purple color, and strings are displayed in
green color.

Astring is a sequence of characters placed under quotation


marks such as ”Hello World” as can be seen in the above
example.
Class work

1. Use the print() function and display your full name on


the screen using the interactive interpreter.

2.Compare and contrast the three types of programming


languages.

3.Why are logic errors more difcult to fix than syntax


errors?
Using the Text Editor

Python codes can be written in a file using the text


editor of Python’s IDLE.
The code that is kept in such files is known as a
script.
Afle that keeps Python scripts is saved with the .py
extension and is called a script file
A Script file can be easily created by selecting
“New File” from the “File” menu in the IDLE’s
interactive interpreter.
Then the text editor is opened in a separate
window..
Variables and Data Types
Variables are computer memory locations.
They are the means to store data in computer memory.
A Variable is used every time user data or intermediary
data is needed to be kept.

In Python variable is created along with its value. Values


are assigned to variables using the assignment (=)
operator, which has two operands
The operand to the left of the operator is always a variable
while the operand to the right of the operator is either a literal
value or any other type of expression.
The following example demonstrates how a variable
named“x” is created with the value 5 in the interactive
interpreter.
>>>x=5

The example that follows shows how a variable named“y”is


created and assigned to the result of an expression. The value
of“y”would be the sum of 5 and 9,which is 14.
>>>y=5+9
Identifier
The name that is given to variables is called an identifier.
Identifiers are a string of one or more characters and have
to conform to some rules in Python to be considered
valid. The rules of identifiers are:
• The first character should be either a letter or an
underscore ( _ ).
• If the identifier is made up of more than one character,
the characters after the
first one should be a letter, number, or underscore.
•AnidentifercannotbethesameasanyofthekeywordsinPyth
on.
• Identifiers are case-sensitive. (For instance, x and X are
considered as different identifiers in Python)

Keywords in Python
and del from not while as elif global
or with pass
assert else if yield break
except import print
class exec in raise
continue fnally is return
def for lambda try
Keywords are reserved words that have predefined
meanings in a programming language.
According to the above rule, the following are valid
identifiers:
X
area
area_5
x5

The identifiers given below, on the other hand, are not valid
identifiers as they violate the rules stated above.
1x
*_5
while
X_&
Class work
1. Identify the valid identifiers and explain why they
are so.
a.x
b.1x
c._x
d.x*y
e.3x
Data Types
A data type is a classification that specifies the type
of values a variable can have, and the type of
operations defined on the values.
Integer (int), floating-point number (float), string
(str), and Boolean (bool) are some of the major
built-in data types in Python.

Floating point numbers are numbers with decimal


points that represent real numbers.
Built-in data types are data types that are built into
the Python language..
The data type of variables in Python is set when
values are assigned to the variables.
If an integer number is assigned to a variable, the
variable will be of type int.
If a string is assigned to a variable, the variable
then will be of type str.
The following example in the interactive interpreter
shows how data types are set to variables based
on the value assigned to the variables.
Class Work
1.Write the results of the following
expressions.
a. 10%2 =________________
b. 2.5**3 =________________
c. 11//3 =________________
Writing a Simple Program
Programs normally accept input and process the
input to produce an output.

As shown in the preceding sections, the print()


function is used to produce output on the IDLE
shell.

As shown in multiple examples in the preceding


sections, the print() function has the following
syntax:

print([value])
A function is a piece of code that performs some
task and is called by its name.

It can be passed data as input to operate on, and


can optionally return data as output.

print(), input() and type() are examples of


functions.

In the above syntax, the name of the function is


print. The value that is given to the print() function
as input can be any type of expression that
evaluates to some value.
To accept input from the keyboard, the
input() function is used.

The input() function has the following


syntax.

variable_name=input([prompt]
The following example demonstrates how the
input() and the print() functions are used in a
program.
It shows how the input() function is used to accept
data from the keyboard, and how the print()
function is used to display the result on the
screen.
The program simply accepts the radius of a circle
from the user and displays the area and
circumference of the circle.
PRACTICAL LAB CLASS BASICS OF PYTHON
Dear Students you are requested to
write the following codes on Python
IDLE.
Note:Follow steps
1. click window
2.Write python IDle
3.Go file >>> New file
4.Save as (write your name)
5.ok (save)
6.write your code (code )
7.Save
8.Run (F5)
PRACTICAL LAB CLASS BASICS OF PYTHON
Print function and input

Python Code-1
print("Hello world!")
name = input("What is your name?")
print("Hello ", name)

Python Code-2

print("This is my first message")


print("This is my second message")
print("This is my last message")
Python code 3

MyName = "Fabrizio"
MyAge = 13
print("Hello", MyName)
print("You are", MyAge, "years old")

Python code -4

MyName = input("Enter your name")


MyAge = input("Enter your age")
print("Hello", MyName)
print("You are," MyAge, "years
old")
Python code -5

print("Welcome to the weather program")


Weather = input("What is the weather like
today?")
print("Today it is", Weather)

Python code -6
number = 10
guess = input("Guess what the number is?")
print("Your number was", guess, "and the actual
number is", number)
Python code -7
1. Number = 10 * "Bob"
print(Number)
2. Result = "a" + "b"
print(Result)
3. Result = 10 - 20.5
print(Result)
4. Result = 0.3 + 0.8
print(Result)
5. Result = 0.3 + "hello"
print(Result)
6. Result = 3 / "hi"
print(Result)
7. Result = 3 * "1"
print(Result)
8. Result = 3 * 1
print (Result)
Python code -8
Number1 = input("Enter a number")
Number2 = input("Enter a second number")
print(Number1 + Number2)
Correct VS incorrect program
(Syntax errors)
Incorrect Python code -9
Animal = INPUT("Enter the name of an animal")
Colour = input(Enter a colour)
output("I've never seen a" Colour Animal)

1.Please write the Correct Python code on


the IDLE !!!

You might also like