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

Getting_Started_with_Python

This document serves as an introductory guide to Python programming for Class 11 students, covering its history, features, installation process, and basic programming concepts. It highlights Python's ease of use, cross-platform compatibility, and object-oriented nature while also addressing its limitations. Additionally, it provides instructions on using Python IDLE, writing scripts, and taking user input, along with examples and programming tasks for practice.

Uploaded by

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

Getting_Started_with_Python

This document serves as an introductory guide to Python programming for Class 11 students, covering its history, features, installation process, and basic programming concepts. It highlights Python's ease of use, cross-platform compatibility, and object-oriented nature while also addressing its limitations. Additionally, it provides instructions on using Python IDLE, writing scripts, and taking user input, along with examples and programming tasks for practice.

Uploaded by

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

Class 11

Getting Started with Python


For Computer Science and Informatics Practices students’

Hopefully, all of you go through the previous uploaded materials. In this material we discuss about the introduction
of Python.

As all of you are the beginners ……….so go through the whole discussion very carefully……..try
to understand the matter………..and think two things when you try to write program 1) what to
do 2) how to do………….as “writing program” is not based on memorizing, is totally based on
clear understanding…………………..

Python programming language was developed by Guido Van Rossum in February 1991.

Python is based on or influenced with two programming languages:

 ABC language, a teaching language created as a replacement of BASIC and


 Modula-3

The programming language was named after famous BBC comedy show namely Monty Python’s Flying
Circus.

It is presently owned by the Python Software Foundation(PSF).

Important Features of Python:

 Easy to use i.e very very programmer friendly


 Platform independent / cross platform language – python program can run across different platforms like
Windows, Linux/unix, Mac Os etc.
 Expressive language – Fewer lines of code and simpler syntax compare to other programming languages
 Readability – Python programs use clear, simple, concise instructions that are easy to read and understand
 Object Oriented Language – It supports the concept of object oriented programming
 Free and Open source – freely available without any cost, source code is also available.
 Interpreted language – interpreter works here not compiler. It interprets and executes the code line by line.
 Higher Productivity – Python supports small codes and extensive libraries.

Some Minuses of Python:

 Not the fastest language – as python is an interpreted language so it not as faster like a compiled language
 Lesser libraries than other language – Python offers library support for almost all computing programs,
but its library is still not competent with languages like C, Java, Perl etc.
 Not strong on Type binding – Python interpreter is not very strong on ‘Type mismatch’ issues. for example
if you declare a variable as integer but later you store a string value in it. python won’t complain you.
 Not easily convertible – Translating a Python programs into other programming language is not so easy.
Installing Python:

To install Python in your computer, you must first download the installation package from following website link:

https://www.python.org/downloads/

You can download any version like python 3.6, or python 3.7 or python 3.8…………….no problem

(Note: Just remember one thing…..if you are using windows 7 then to install python 3.6 or above it requires
service pack 1……so first install service pack 1 then install python……..for other operating system like
windows 8 or windows 10…it creates no problem)

After download the executable installer(32 bit / 64 bit as per your system)…………..then open the downloaded file
to install it on your computer.

I discuss the steps to install python 3.7.4 version in following:


After successful installation you see the following screen:

Now, your python installation is complete.

Interacting with Python(Python IDLE):

To write and run our python programs interactively, we can use either command line window or the IDLE. IDLE is a
simple Integrated Developing Learning Environment that comes with Python installation.

How to open Python IDLE:

Click on start menu on your computer  then find the python apps (or click all programs – for windows 7)  click
on IDLE option.

When you click on IDLE option you can see the following Python shell which looks like following:
Python shell – It is an interactive window where you can type the python code or commands and see the
output in the same window. It is an interface between Python commands and the operating system.

In the above figure, we type the “Welcome” in front of >>> symbol(called python prompt) and then press Enter.

Then what happened?

As soon as we press the Enter key, the command gets executed immediately and the output is displayed then and
there in the next line.

In the above window i.e. on Python shell there is not the provision for holding or saving commands that we typed in
python prompt. All these commands, along with their output, get cleared as soon as we close the python shell
window.

This limitation can be overcome by working in python script mode. In Python script mode we can save all
commands we are typing.

How to open Script mode:

Click on File menu  then click on new file option on python shell………
When you click on New File option…..it opens a new window…where you can write the python commands:

After typing your commands then we save the file by clicking File menu  then Save option

Then choose the location where you save your program then give the file name like example.py then click on save
button.

(Note – python program extension is .py)

Now, to see the output of your program……you should run the program as following:

click on Run menu  then click on Run Module or Press F5 key.


Now, you can see the output on the python shell:

Hopefully, the above process is clear to all……………….

Remember the following points:

We can write our python programs either in interactive mode or in script mode.

The python program should be saved with the extension .py

[ You can run your python program by using another software named Anaconda Distribution. Anaconda distribution
provides the following tools that you can use to work in python. 1) Jupyter notebook – It is a web based, interactive
computing environment and 2) Spyder – It is a powerful Python IDE with many useful features. ]

Now, to write our own program, we have to know about two things, (i) How to display output in python and
(ii) How to take input from the user.

[Note: Don’t mix up the two terms – programmer and user…………..programmer are the persons who write
programs using some programming language and knows everything about the program.

whereas ….user are those persons who just use the program without any knowledge of programming…….]

Ok……now come to the topic again……..

print( ) – to print or display output in python, we have to use the pre-defined function print( ).

syntax: print(objects to be printed)

Example:

print(“HELLO World”)

then it gives the output:

HELLO World

(Note: remember one thing – python is a case sensitive language………so if your write PRINT( ) or Print( ) in
place of print( ), it will shows error. )

Different uses of print( ) function:

Program:
Output:

Program:

Output:

So, it is clear that print( ) is used to display output and every print( ) displaying output in separate line.

Now, if we want to display the output of the above program in same line then our program is:

Output:

Explanation:

on the above statement, end is used within print( ) function, it is known as argument or parameter of print( )
function.

So, end argument is used to specify the end character of every print statement.

On the above example I specified three spaces using end argument so it gives the output by separating “HELLO
WORLD” and “Welcome to python” with three spaces but in single line.

If we change our code as follows:

Then the output is:


print( ) function also supports another argument sep.

sep is used to specifying the separating character in a single print statement.

Look at the following example:

What is the output of the above statement?

output is:

Means, if you not mention sep argument then words are separated by single space normally.

Now, if we write:

the output is:

Now, the conclusion is:

print( ) function is used for displaying output on screen in python and it supports two arguments (i) end and
(ii) sep.

Taking user input:

input( ) – input( ) function is used to take input from the user.

So, after taking the input from the user we must store the value for further use. In this point the concept of variable

comes in program.

variable is a named storage location whose value will vary during the program execution.

Let take one simple example:

if I write: x2
then ‘x’ is a variable here, and whatever value of x you specify every time, it will produce the output based on the
given value.

if you give, x = 5 then the output should be 25

if you give, x = 3 then the output should be 9

So, the value of x will vary during the program execution.


important points regarding variable:

variable names should be starting with a letter.

you can not use any reserved word of python as variable name.

you can not use any special symbol in the variable name except underscore( _ ).

you can use digits in variable names but not as the first charcter.

Some valid variable names shown below:

a, ax, x1, arambagh, my_var

invaid names examples:

1x - invalid, as starting with digit

a+b - invalid, as special character (+) present

ab - invalid, as special character space is present

my-var - invalid, as special character ( - ) present

break - invalid as ‘break’ is a reserved word in python

( I will discuss about reserved word of python later).

Example of taking input from the user:

On the above statement whatever values given by the user that must be stored in a variable named as ‘n’.

Uses of input function:

Program Example: Take the name from the user as input and print his/her name with a welcome message.

Output:
Now, if we want to solve the following problem:

Program Example: take the user’s age then print it after adding 10 with the age.

then our program is:

Then if you run the above program, after entering the age and when you press Enter
key…………………………….it shows an error………………instead of showing 25

Think,………….. why?

The reason is input( ) function always takes string type values. string means combination of characters……..

we given 15 as age but 15 is a number for ourselves not for the computer. It treats 15 as a string value……..so
addition of string is not possible…………

“ram” + “15” ………….. is this possible?

never………….that’s why it shows an error.

Then what is the solution for the above problem:

we should convert the string type into numeric type at the time of taking input from the user.

so, our correct code is:

here int indicates an integer. It is known as ‘datatype’ in python.

if you want to accept decimal number from user then your code should be:

here, float indicates floating point number.

(I will discuss other data types in details in my other material………………….now, the concept of three data
types is enough to write our programs at the initial level………..

int – used for integer type (means whole number)

float – used for floating point number(means with decimal point)

string – is used for combination of characters.)


for your knowledge:

print(“HELLO World”)
both indicates string type value
OR

print(‘HELLO World’)

so, in Python string must be enclosed within single quote(‘ ’) or double quotes(“ ”).

Now, come to our program:

Program Example: take the user’s age then print it after adding 10 with the age.

Solution)

Output:

Program Example: take the user’s age(in decimal points) then print it after adding 10 with the age.

Output:

If you want to display some message in output then you change your program as follows:

Output:

So, everything is depends on you…………as you are the programmer.


Python, decide the variable type based on the value stored in it…………that is one of the advantage of
python.

if you write, x = 25, then here x is an integer type variable

if you write, x = 17.25, then here x is a floating point type variable

if you write, x = ‘Ram’ or x = “Ram” , then here x is a string type variable

Some operators used in python(only for developing introductory programs……I will discuss all operators
later on)

+ - for addition

- - for subtraction

* - for multiplication

/ - for division

% - for remainder

= - for assignment

Now, try to solve some programs which I discussed in my previous materials (on flowcharts):

Program: to find the sum of two numbers.

Flowchart:

Program:

Output:
Task: Write python programs:

1) Find out the addition two floating point numbers.


2) Find out the subtraction of two numbers.
3) Find out the multiplication of three numbers.
4) To convert the temperature from Celsius to Fahrenheit
5) To convert the temperature from Fahrenheit to Celsius
6) Find out the average of two numbers
7) To find the area and perimeter of a Square
8) To find the area and perimeter of a Rectangle
9) To find out the simple interest
10) Find out the square and cube of a given number.

Try to solve all the tasks above.


If any problem then message me in my personal whatsapp no. 8145472773

You might also like