Programming Grade 7 (2)
Programming Grade 7 (2)
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.
>>>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.
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.
print([value])
A function is a piece of code that performs some
task and is called by its name.
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
MyName = "Fabrizio"
MyAge = 13
print("Hello", MyName)
print("You are", MyAge, "years old")
Python code -4
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)