[go: up one dir, main page]

0% found this document useful (0 votes)
78 views8 pages

Introdution To Python

Python is a high-level, interpreted and general-purpose programming language that focuses on code readability. It was developed by Guido van Rossum in 1991 and named after the BBC comedy show Monty Python's Flying Circus. Python has two basic modes - interactive mode, where code is executed immediately, and script mode, where code is saved in a file with a .py extension and run as a program. It is an interpreted language, freely available, portable across different platforms, and has a variety of uses including web development, scripting, and data analysis.

Uploaded by

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

Introdution To Python

Python is a high-level, interpreted and general-purpose programming language that focuses on code readability. It was developed by Guido van Rossum in 1991 and named after the BBC comedy show Monty Python's Flying Circus. Python has two basic modes - interactive mode, where code is executed immediately, and script mode, where code is saved in a file with a .py extension and run as a program. It is an interpreted language, freely available, portable across different platforms, and has a variety of uses including web development, scripting, and data analysis.

Uploaded by

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

INTRODUTION TO PYTHON

WHAT IS PYTHON
Python is a high-level, interpreted and general-purpose programming language that
focuses on code readability. The syntax in Python helps the programmers to do
coding in fewer steps as compared to Java or C++.
WHO DEVELOPED PYTHON
Python was named after famous BBC comedy show namely Monty Python’s Flying
Circus. It was develop by Guido Van Rossum in 1991

FEATURES OF PYTHON

1. Easy to learn & use – It is a compact and easy to use object oriented language
with very simple syntax rule.

2. Portable/cross platform – it runs equally well on variety of platforms like


Windows, Linux/Unix that is why it is truly cross platform language or portable
language.

3. Free and Open Source – It is freely available without any cost .

4. Interpreted language – it is an interpreted language. This means that Python


installation interprets and executes the code line by line at a time. That is why
it is an easy to debug language.

5. Expressive Language – It is more capable to expressing the code’s purpose than


many other languages.

6. Completeness – When install Python, you get everything to do the real work.
No need to download or install additional libraries.

7.Variety of Usages/Applications – As it is a powerful language it is used in


Scripting, Web Applcations,Game development, Database Applications.

Python has two basic modes : Script mode & Interactive mode

Interactive mode – It is a command line shell which gives immediate result for
each statement. To start in interactive mode simply type python” without any
arguments. >>> it shows that you are in interactive mode. In this mode what
you type is immediately run. If you type 1+1, it will display 2. Interactive mode
allows you to test out and see what Python will do.
Example :- >>>2
It will print 2 on the screen
>>> ( 2*5)
It will print 10 on the screen
SCRIPT MODE
In Script mode , you will write a script and then run it. The script is saved with .py
extension.
What is Character Set?
Character set is a bunch of identifying elements in the programming language.
Letters:- A-Z, a-z
Digits:- 0 to 9
Special Symbols:- space + - / ( ) [ ] = ! = < > , ‘ “ $ # ; : ? &
White Spaces:- Blank Space , Horizontal Tab, Vertical tab, Carriage Return.
Other Characters:- Python can process all 256 ASCII and Unicode Characters.
COMMENTS IN PYTHON :Comments can be added to python scripts to
describe the purpose of statements. It start with # ( hash character) .
and Python will render the rest of the line as a comment:
Comments can be used to explain Python code. Comments starts with a #, and
Python will ignore them:
#This is a comment.
Print("Hello, World!")
Python Operators
Operators are used to perform operations on variables and values.
Python divides the operators in the following groups:
Arithmetic operators
• Addition
x=5
y=3
z=2.3
p=2.1
Print(x + y) #ans 8
Print(x+z) #ans 7.3
Print (z+p) #ans 4.4
• Division
x = 12
y=3
Print(x / y) #ans 4
• Modulus
x=5
y=2
Print(x % y) #ans 1(reminder)
Exponentiation
x=2
y=5
Print(x ** y) #same as 2*2*2*2*2 or(25)

Programs
Q1.program to enter 2 numbers and show the sum,Division,and subtraction
of those two numbers
Q2.Program to enter length and breadth of a rectangle and find area of a
rectangle
Q3Program to find square of a given number.
Q4.Program to print half of a given number

Ans- QS-1
>>>a =10
>>>b=30
>>>sum = a+b
>>>div = a/b
>>>sub = a-b
>>>Print (sum)
>>>Print (div)
>>>Print (sub)

Ans-QSNO-2
>>>length=20
>>>breadth=10
>>>area=length*breadth
>>>Print (area)

Ans-QSNO-3
>>side=20
>>Square=side*side
>>Print (square)
Ans-QS4
>>a=60
>> Half=a/2
>>Print (half)

Expression using python


1/2xyz=
Ans-0.5*x*y*z
an/bn =
Ans-(a**n)/ (b**n)
3x2+2x-5=
Ans:3*(x**2) +2*x+5
• To assign number 12 to variable
Ans K=12
• To assign number 3.4 to variable p and q
Ans: p=q=3.4
• To display the text India is my country
Ans print (“India is my country”)
• To display value of 34
Ans print (3**4)
DATA TYPES : Data can be of many types that is character,integer,real,string
etc. Anything enclosed in quotes represents string data in Python. Numbers
without fractions represent integer data. Numbers with fractions represents
real data.
INTEGERS : These are the whole numbers such as 5,39,10 etc.
FLOATING POINT NUMBERS :A number having fractional part is a floating point
number. example – 3.154,here the decimal point tells it is a floating point
number,not an integer.
STRING : String are the values that hold characters in quotation marks. Both
single and double quotation marks can be used that is
“Kelvin” , “63”
INPUT ()FUNCTION : In Python input function is used to accept the values from
the keyboard.
Variable name = input(statement)
Example : name=input(“enter your name”)
If you want to accept any integer value then
Variable name = int(input(statement))
Example : num1=int(input(“enter a number:”))

Program to obtain three nos. and print their sum.


num1= int(input(“enter number1:”))
num2=int(input(“enter number2:”))
num3=int(input(“enter number3:”))
Sum = num1+num2+num3
print(“three numbers are:”,num1,num2,num3)
print(“sum is :”, sum)

Program to obtain length & breadth of a rectangle.


length= int(input(“enter length:”))
breadth=int(input(“enter breadth:”))
area=length * breadth
print(“length =“,length)
print(“breadth= ”, breadth)
print(“area=“,area)
Program to input a number and print its cube.
num= int(input(“enter number:”))
cube = num*num*num
print (“number is”,num)
print(“its cube is”,cube)

Program to input two numbers and swap them.


n1= int(input(“enter number 1:”))
n2= int(input(“enter number 2:”))
print(“original numbers :”, n1,n2)
n1=n2
print(“after swapping :”, n1,n2)

Program to find out average of three numbers.


num1= int(input(“enter number1:”))
num2=int(input(“enter number2:”))
num3=int(input(“enter number3:”))
avg=(num1+num2+num3)/3
print(“average of given numbers:”,avg)

Program enter temperature in Celsius and display in Fahrenheit.

cel = int(input("Enter the Temperature in Celsius :"))


fa = (1.8 * cel) + 32.
print("Temperature in Fahrenheit :", fa)

Program Input your height in centimeters and display in Ft and Inches.


cen=int(input(“enter the height in centimeter :”))
inch=0.394*cen
ft=0.0328*cen
print(“length in inches:”,inch)
print(“length in feet:”,ft)
Program to Input two numbers and print their remainder

num1 = int(input("Enter the first number: "))


num2 = int(input("Enter the second number: "))
res = num1 % num2.
print("remainder is :", res)
Program to Input time in minutes and print it in seconds

min = int(input("Enter time in min: "))


second = min * 60
print(min, "=", seconds)
Program to Input base and height of a triangle and print its area as ½ × base
×height.

base= int(input("Input the base : "))


height = int(input("Input the height : "))
area = base*height/2
print("area = ", area)

1 MARK QUESTIONS
1. Python is an ____________ language.
a) High level b) Object oriented c)Procedural d) difficult
2. Python uses an ____________ to convert source code to object code
a) Interpreter b) Compiler c) Combination of both A &B d)
Special virtual engine
3.Python code can run on a variety of platforms, it means Python is a ______
language.
a)graphical b) cross-platform c) independent d) all of these
4.Python programs are type in
a)Interactive mode b)Script mode
c) A combination of interactive & script mode d) All of these
5.The __________ mode of Python gives instant result of typed statement.
a)Interactive mode b)Script mode
c) A combination of interactive & script mode d) All of these
6.To print the value of a variable, Python uses
a)Print statement b)Print ( ) function
c) Print statement d)Print()function
8. Python is a high level language.
9. Python’s two working modes are : Interactive mode and Script mode.
10.The shortcut key to run a Python program from script mode is F5
11.Python programs/scripts are stored in files with .py extension.
12. What is the difference between Interactive mode & Script Mode in Python?
Ans : In Interactive mode, instructions are given in Python prompt( e.g.. >>>).
Python carries out the given instruction and shows the result there itself. Where in
Script mode, Python instructions are stored in a file generally with .py extension
and are executed together in one go as a unit. The saved instructions are known as
Python script or Python program.
13. What will be the output of the following code :
# This is a sample program
# print (“such as”)
Print(“take every chance”)
Print(“Drop every fear”)
a) such as b) such as c)take every chance
take every chance take every chance drop every fear
drop every fear drop every fear
14.Who developed Python Programming Language?
a) Wick van Rossum b) Rasmus Lerdorf
c) Guido van Rossum d) Niene Stom
15. Why is Python such a widely used programming language?
a. Easy to learn
b. Portability and compatibility
c. A Broad Standard Library
d. All of the above
16. Python is a _________ programming language, which means it runs on a
variety of platforms including Windows, MacOS, Linux, and the Java
and.NET Virtual machines.
a. Cross-platform
b. Single-platform
c. Code-platform
d. None of the above
17. IDLE stands for ____________.
a. Integrated Development and Learning Environment
b. Internal Develop and Learning Environment
c. Inside Development and Learning Environment
d. None of the above.
18. A _________ is a piece of text that doesn’t impact the outcome of a
programme; it’s just a way to tell someone what you’ve done in a programme or
what’s going on in a block of code.
a. Statement
b. Comments
c. Nodes
d. None of the above
19. A _________ is a type of variable whose value cannot be changed.
a. Constant
b. Statement
c. Identifier
d. None of the above
20. Numbers with fractions or decimal points are called ________ datatype.
a. Integer
b. String
c. Float
d. None of the above
21. _________ function is used to given output in python.
a. printf()
b. print()
c. scan()
d. None of the above
22. _________ function is used to take input from the user in python.
a. Input()
b. Insert()
c. Store()
d. None of the above

You might also like