0% found this document useful (0 votes)
41 views5 pages

Python Lecture1

Python is a programming language that is easy to understand and use. It allows users to write instructions called code to perform tasks and operations. The code is written in Python syntax which resembles the English language. Python code can be used to create websites, games, programs, and more. Key aspects of a Python program include variables to store values, data types to specify what type of data a variable holds, and functions like print() and input() to display output and get user input.

Uploaded by

Moomal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
41 views5 pages

Python Lecture1

Python is a programming language that is easy to understand and use. It allows users to write instructions called code to perform tasks and operations. The code is written in Python syntax which resembles the English language. Python code can be used to create websites, games, programs, and more. Key aspects of a Python program include variables to store values, data types to specify what type of data a variable holds, and functions like print() and input() to display output and get user input.

Uploaded by

Moomal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 5

PYTHON

Programming Languages:

INPUT- The instructions provided to the computer by users like us in order to perform a task.

PROCESS- The computer reads and understands our instructions in order to perform our task.

OUTPUT- The result of the computer’s process based on the instructions provided by us.

Instructions- The instructions that are provided must be in a proper specified format and there
can’t be any changes in the format. These instructions altogether are called the program or the
code.

Errors/Mistakes- These are encountered by the computer when the instructions provided by
the users don’t make sense to it. This mostly happens when we don’t provide instructions in the
proper format or due to some basic grammatical/ human errors from the user’s side.

Various types of Programming Languages- Just like we speak in English, Hindi or Marathi i.e
we have multiple ways of communicating with people. The choice of a language is purely based
on one’s comfort/dialect/mother tongue. Similarly, we have the choice of providing instructions to
the computer in any language of our choice. But in this case, these languages are known as
Programming Languages.

Examples of Programming Languages- C, C++, Java, Python, PHP, etc.

What is Python?

It is a programming language, and is also considered to be one of the easiest amongst others.
Instructions/ programs/ codes can be written in Python to get a job done. The computer
processes this code and returns an output.

Features Of Python:

➢ Easy, Simple and understandable.


➢ It can be used on any kind of machine or computer i.e it is platform independent
➢ The way of writing the program/ instructions is very similar to the English language and
hence it is easy to understand. The syntax(format) is simple.
➢ The computer also understands the program very easily without much effort. Hence it is
also called an interpreted language.
➢ It is an open-source language i.e it is free to use for everyone.
Applications of Python:

➢ Creating a web page or website of our choice and design.


➢ Invent and create games/ applications
➢ Program robots i.e to make robots function according to our desire.
➢ Making complex calculations and scientific computations.
➢ Artificial Intelligence like robots

Structure Of A Python Program:

1. Write instructions specified to take an input from users.


2. Instructions to tell the computer about some values or facts.
3. Instructions to calculate or compute a task.
4. Instructions to specify the way in which a result of the program should look like.

From the above mentioned structure, we will learn about the first two steps:

Variables:

Variables are nothing but a storage space which we have created in order to store some values/
facts or an input taken from the user. This storage space is created inside the computer
memory. Each variable can store only one value at a time. If a new value is written again, then
the previous value is deleted and the new one is stored.

While writing variables we use the assignment operator(=), which is nothing but the equals-to
symbol. Examples are as follows:

a=10, b=4, c=10-4, d= 45-b

In the above statements, a, b, c, d are variables/ variable names and 10, 4, 10-4, 45-b are the
values. These values are stored/ assigned to the variable. For eg, the value 10 is stored inside
a, the value 10-4 is stored inside c.

There are some instructions required to write variable names(refer book page no. 94)
Data Types:

A data type in simple words is the type of information/ value which we’ll be storing inside a
variable. There are different data types such as:

1. Integer: They are nothing but numeric values that consist of digits and numbers. The only
restriction here is that it has to be a whole number i.e a number without decimals. Eg: a=10 is
an integer data type but a=10.75 is not accepted as integer. There are three types of integers.In
order to specify a variable as integer type, we write ‘int’ in the program

➢ Integer(int): Consisting of digits ranging from -2147483648 to +2147483648


➢ Long Integers(long int): Consists of digits beyond the range mentioned above.
➢ Boolean(bool): Values representing only two scenarios like True, False/ Off, On/ Yes, No

2. Float: They are numeric values which can contain fractions as well as normal integers.
Numbers with decimals can also be stored inside variables for float data type. In order to specify
a variable as float type, we write ‘float’ in the program.

3. String: This data type is used to specify that the value assigned to a variable consists of
alphabets, letters or characters. In order to specify a variable as string type, we write ‘str’ in the
program. For example:

str a=”harsh”
str b=’samaira’

In the above statements, a and b are the variables, str is the data type(specifying that the value
of variable contains letters). The string value must always be written inside “ “ or ‘ ‘ .

The print() function:

It is used to print a message or any kind of text as a result. The message to be printed doesn’t
need to be in any specified format as it can be whatever you want. The syntax is as follows:

print(“This is a class of Python”)


print(‘Python is very interesting’)

Whatever text a user wants to display, it must be inside “ “ or ‘ ‘


Apart from displaying the text of our choice, we can also display the values of variables.

Below is an example of a simple python program:


Example 1 : a= 10
print(a)

Example 2: a=10
b=20
c=25
print(a,b,c)

To print the values of different variables at the same time, you must use the (,) separator inside
print() function.

The input() function:

In order to tell the computer that a user wants to provide his input/ value, this function is used. It
is used to accept the value of a variable from the user. The data type of the variable can be
specified using int() or float() functions.

The syntax to use the input function:

A = input(“Any text of your choice”)

Here, A is the variable name for which we are asking the value from the user. The above
statement will take the input as a STRING type. If we want to take input as integer or float type,
then we need to write the code as follows:

A= int(input(“Text of your choice”))


A= float(input(“Text of your choice”))

Python program to add two numbers by user input:

a= int(input(“Please enter the value of a: “)


b=int(input(“Please enter the value of b:”)

sum= a+b

print(“The sum of the numbers is “ , sum)

In the above program, a and b are the variables for which an input is taken from the user. The
int() function is used to specify that the values entered by the user will be of numeric form. Later
the ‘sum’ variable is written to perform the computation of addition. At last, the sum is printed in
the given format.
Python program to add two numbers without user input:

a=10
b=20
sum=a+b
print(sum)

In the above program, the values of the variables a and b are written by us in the program itself.
Hence it is directly printed on the screen as a result.

You might also like