Вы находитесь на странице: 1из 12

PYTHON PROGRAMMING LANGUAGE

Python is a widely used general-purpose, high level programming language. It was initially
designed by Guido Van Rossum in 1991 and developed by Python Software Foundation. It
was mainly developed for emphasis on code readability, and its syntax allows programmers
to express concepts in fewer lines of code.
Python is a programming language that lets you work quickly and integrate systems more
efficiently.
There are two major Python versions- Python 2 and Python 3. Both are quite different.

Keywords in Python: Python language also reserves some of keywords that convey
special meaning. Knowledge of these is necessary part of learning this language. Below is list
of keywords registered by python .

False True as break continue


Elif except for global import
Lambda not pass return while
None and del class def
Else is from if in
Nonlocal or raise try with

Statement, Indentation and Comment in Python:


Instructions written in the source code for execution are called statements. There are different
types of statements in the Python programming language like Assignment statement,
Conditional statement, Looping statements etc. These all help the user to get the required
output. For example, n = 50 is an assignment statement.

Multi-Line Statements: Statements in Python can be extended to one or more lines


using parentheses (), braces {}, square brackets [], semi-colon (;), continuation character
slash (\). When the programmer needs to do long calculations and cannot fit his statements
into one line, one can make use of these characters.

Data Types:
 Numeric data types
a. Integer
b. Float
c. Complex
 Strings
 List
 Tuples
 Sets
 Dictionary
 Arrays
Name Year
……............................................. …......................................
Subject Class
……............................................ ….....................................
Semester
…............................................ Roll No ….................................
INDEX
Experiment Experiment Submission
S.No. Remarks/signature
Description Date Date
Write a program to print
1
“Hello, World”.

Write a program to calculate


2 various arithmetic operations
of two numbers.
Write a program to find
3 entered number is “even” or
“odd”.
Write a program to calculate
4 the factorial of entered
number.

Write a program to calculate


5
square root of any number.

Write a program to calculate


6
power of any number.

Write a program to check


7 whether number is prime or
not.

Write a program to swap two


8
values.

Write a program to check


9 whether number is ‘positive’,
’negative’ or ‘zero’.
Write a program to find
10 largest number among three
numbers.
PROGRAM : 01
Write a program to print “Hello, World”.

print(“Hello, World”)

OUTPUT:
PROGRAM : 02
Write a program to calculate various arithmetic operations of two
numbers.

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


num2=int(input("Enter second number"))
addition =num1+num2
subtraction =num1+num2
multiplication =num1+num2
division =num1/num2
modulus=num1%num2
print(“Addition =” ,addition)
print(“subtraction =” ,subtraction)
print(“multiplication =” ,multiplication)
print(“Division =” ,division)
print(“Modulus =” ,modulus)

OUTPUT:
PROGRAM: 03
Write a program to find entered number is “even” or “odd”.

num=int(input("Enter number"))
if num%2==0:
print("Number is even")
else:
print("Number is odd")

OUTPUT:
PROGRAM: 04
Write a program to calculate the factorial of entered number.
num=int(input("Enter number"))
factorial = 1
if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",num,"is",factorial)

OUTPUT:
PROGRAM: 05

Write a program to calculate square root of any number.

from math import sqrt


num = float(input('Enter a number: '))
z=sqrt(num)
print("the squre root of entered number is " ,z)

OUTPUT:
PROGRAM: 06

Write a program to calculate power of any number.

from math import pow


num=float(input("Enter number: "))
power=int(input("Enter power: "))
value=pow(num,power)
print("The power of entered number is: " ,value)

OUTPUT:
PROGRAM: 07

Write a program to check whether number is prime or not.

num = int(input("Enter a number: "))


if num > 1:
for i in range(2,num):
if (num % i) == 0:
print(num,"is not a prime number")
print(i,"times",num//i,"is",num)
break
else:
print(num,"is a prime number")
else:
print(num,"is not a prime number")

OUTPUT:
PROGRAM: 08

Write a program to swap two values.

x = input('Enter value of x: ')


y = input('Enter value of y: ')
temp = x
x=y
y = temp
print('The value of x after swapping: {}'.format(x))
print('The value of y after swapping: {}'.format(y))

OUTPUT:
PROGRAM: 09

Write a program to check whether number is ‘positive’ ,’ negative’ or ‘


zero’.

num = float(input("Enter a number: "))


if num > 0:
print(" Entered number is Positive number")
elif num == 0:
print(" Entered number is Zero")
else:
print("Entered number is Negative number")

OUTPUT:
PROGRAM: 10

Write a program to find largest number among three numbers.

num1 = float(input("Enter first number: "))


num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))
if (num1 >= num2) and (num1 >= num3):
largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3
print("The largest number between",num1,",",num2,"and",num3,"is",largest)

OUTPUT:

Вам также может понравиться