0% found this document useful (0 votes)
2 views19 pages

Subrat Python

The document contains a series of Python code snippets demonstrating various programming concepts such as printing output, arithmetic operations, data types, control flow, functions, and data structures. It also includes examples of using libraries like math and matplotlib for mathematical operations and plotting. Overall, it serves as a practical guide for beginners learning Python programming.

Uploaded by

naiksubu23
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)
2 views19 pages

Subrat Python

The document contains a series of Python code snippets demonstrating various programming concepts such as printing output, arithmetic operations, data types, control flow, functions, and data structures. It also includes examples of using libraries like math and matplotlib for mathematical operations and plotting. Overall, it serves as a practical guide for beginners learning Python programming.

Uploaded by

naiksubu23
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

In [1]: print("Hello World")

Hello World

In [2]: print(20+50)

70

In [3]: print('20+50')

20+50

In [4]: print('Hello','Welcome to Python class')

Hello Welcome to Python class

In [5]: print(10>5)

True

In [6]: print(2==3)

False

In [7]: print(12*8)

96

In [8]: print("I am a Student")

I am a Student

In [12]: print(2*5==3*5)

False

In [ ]:
In [1]: a=10
print(a)

10

In [2]: a=99
print(a+23)

122

In [3]: print('a')

In [4]: print(id(a))

140736328937448

In [7]: a_2="I am "


b_2="Subrat"
print(a_2+b_2)

I am Subrat

In [8]: a_2="I am "


b_2="Subrat"
print(a_2+" "+b_2)

I am Subrat

In [11]: x= 20
y= 10
print(x+y)
print(x-y)
print(x*y)
print(5*x)
print(x/y)
print(x%y)
print(x**y)

30
10
200
100
2.0
0
10240000000000

In [12]: age = 25
name = "Subrat"
print(name,"is", age,"years old.")

Subrat is 25 years old.

In [18]: print(12//5)

2
In [20]: x = 3
y = 4
print(x==y)
print(x!=y)
print(x<y)
print(x>y)
print(x<=y)

False
True
True
False
True

In [22]: print(x==3 and x>y)

False

In [23]: input("what is your name?")

Out[23]: 'Subrat'

In [25]: print("Kaise Ho"+" "+input("What is your name?"))

Kaise Ho Subrat

In [26]: Name=input("What is the length of the name........?")


Length=len(Name)
print(Length)

In [27]: var_1=6
var_2=11.5
print(type(var_1))
print(type(var_2))

<class 'int'>
<class 'float'>

In [29]: weight=input("What is your weight in Kg? ")


height=input("What is your height in Meters ")
BMI= int(weight)/float(height)**2
print(BMI)
print(int(BMI))
print(round(BMI,0))

25.25951557093426
25
25.0

In [ ]:
In [7]: number = [1, 2, 3, 4, 5]

Days_of_Week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"

Mix_list = [1, "Subrat", 3, 4.5]

print(number)
print(Days_of_Week)
print(Mix_list)
print(Days_of_Week[0])
print(len(Days_of_Week))
print(Days_of_Week[-1])
print(Days_of_Week[2:4])
print(Days_of_Week[2:])
print(Days_of_Week[:4])
print(Days_of_Week[2:6:1])
print(Days_of_Week[2::2])

[1, 2, 3, 4, 5]
['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
[1, 'Subrat', 3, 4.5]
Monday
7
Sunday
['Wednesday', 'Thursday']
['Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
['Monday', 'Tuesday', 'Wednesday', 'Thursday']
['Wednesday', 'Thursday', 'Friday', 'Saturday']
['Wednesday', 'Friday', 'Sunday']

In [10]: a= [1,34,2,5,89,90,23,45,28,21]
print(a)
[Link]()

print(a)

[1, 34, 2, 5, 89, 90, 23, 45, 28, 21]


[1, 2, 5, 21, 23, 28, 34, 45, 89, 90]

In [12]: Days_of_Week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"

Days_of_Week.reverse()
print(Days_of_Week)
Days_of_Week.sort()
print(Days_of_Week)

['Sunday', 'Saturday', 'Friday', 'Thursday', 'Wednesday', 'Tuesday', 'Monday']


['Friday', 'Monday', 'Saturday', 'Sunday', 'Thursday', 'Tuesday', 'Wednesday']

In [14]: numbers = [3, -1, 4, 0, 10]


print(
[Link](11)
print(numbers)
[Link](2, 11)
print(numbers)
[Link]([4, 5, 6])
print(numbers)

[3, -1, 4, 0, 10, 11]


[3, -1, 11, 4, 0, 10, 11]
[3, -1, 11, 4, 0, 10, 11, 4, 5, 6]

In [17]: Days_of_Week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"

numbers = [3, -1, 4, 0, 10]


[Link](Days_of_Week[0:2])
print(numbers)
numbers = [3, -1, 4, 0, 10]
[Link](2, Days_of_Week[0:2])
print(numbers)
Days_of_Week.remove("Thursday")
print(Days_of_Week)

[3, -1, 4, 0, 10, 'Monday', 'Tuesday']


[3, -1, ['Monday', 'Tuesday'], 4, 0, 10]
['Monday', 'Tuesday', 'Wednesday', 'Friday', 'Saturday', 'Sunday']

In [16]: numbers = [3, -1, 4, 0, 10]


numbers[1:3] = [23, 32]
print(numbers)

[3, 23, 32, 0, 10]

In [ ]:
In [1]: List1 = [2, 3, 5, [6, 7, 8], 10, 11]

print(List1[3])

print(List1[3][1])

[6, 7, 8]
7

In [3]: list1 = ["Subrat", "Satyajit", "Rohit"]

for i in list1:
print(i)
if i == "Satyajit":
print("Hi how are you?")
break

Subrat
Satyajit
Hi how are you?

In [4]: numbers = [1, 3, -2, 4, 7, 10]

for i in numbers:
cube = i ** 3
print(cube)

1
27
-8
64
343
1000

In [5]: numbers = [1, -2, 4, 5, -10]

for i in numbers:
print(i)
if i == 5:
break
else:
print("Process completed")

1
-2
4
5

In [6]: numbers = [1, -2, 4, 6, 5, 12, -10]

for i in numbers:
if i % 6 == 0:
print(i)
break
else:
print("No number divisible by 6")

In [7]: a = int(input("Put the value of a: "))


b = int(input("Put the value of b: "))

if a == b:
print("a and b are same")
else:
print("a and b are different")

a and b are different

In [8]: numbers = [1, -2, 4, 5, 4, -10]

for i in numbers:
print(i)
else:
print("Process completed")

1
-2
4
5
4
-10
Process completed

In [9]: numbers = [1, 3, -2, 4, 7, 10]

Square_numbers = []

for i in numbers:
square = i ** 2
Square_numbers.append(square)

print("The list of squares of numbers is:", Square_numbers)

The list of squares of numbers is: [1, 9, 4, 16, 49, 100]

In [11]: list1 = [1, 2, 'Subrat', True]


list2 = [3, -2, 4]

list1[2] = "Satya"
print(list1)

tupl = (1, 2, 'Subrat', True, 1.2)

temp = list(tupl)
temp[2] = "Satya"
tupl = tuple(temp)

print(tupl)
[1, 2, 'Satya', True]
(1, 2, 'Satya', True, 1.2)

In [12]: tup1 = (1, 2, 'Subu', True, 1.2)


tup2 = (3, -2, 4)

print(tup1)
print(tup1 + tup2)
print(tup1[2])

list1 = [1, 2, 'Subu', True]


list2 = [3, -2, 4]

list1[2] = "Satya"
print(list1)

(1, 2, 'Subu', True, 1.2)


(1, 2, 'Subu', True, 1.2, 3, -2, 4)
Subu
[1, 2, 'Satya', True]

In [ ]: tup1 = (1, 2, 'Sachin', True, 1.2)

temp = list(tup1)
temp[2] = "Vidhi"
tup1 = tuple(temp)

print(tup1)

list1 = [1, 2, 'Sachin', True]


list1[2] = "Vidhi"

print(list1)
In [1]: import math as m

print([Link](100))

print([Link](90))
print([Link]([Link](30)))

print([Link]([Link](30)))

print([Link](0))
print([Link]([Link](0)))

9332621544394415268169923885626670049071596826438162146859296389521759999322991
5608941463976156518286253697920827223758251185210916864000000000000000000000000
0.8939966636005579
0.49999999999999994
0.8660254037844387
1.0
1.0

In [2]: import math as M


import math

print([Link])
print(math.e)
print([Link](230, 450))
print([Link](4666, 56))
print([Link](5))

3.141592653589793
2.718281828459045
10
130648
True

In [3]: import math as m

print([Link](100))

print([Link](90))
print([Link]([Link](30)))

print([Link]([Link](30)))

print([Link](0))
print([Link]([Link](0)))

9332621544394415268169923885626670049071596826438162146859296389521759999322991
5608941463976156518286253697920827223758251185210916864000000000000000000000000
0.8939966636005579
0.49999999999999994
0.8660254037844387
1.0
1.0
In [4]: import math as m
import cmath as cm

print([Link](90))
print([Link]([Link](90)))

print([Link]([Link](90)))

print([Link]([Link] / 2))

print([Link](2 * [Link] * 1j))

-0.4480736161291701
6.123233995736766e-17
(1+0j)
1.0
(1-2.4492935982947064e-16j)

In [ ]:
In [1]: import [Link] as plt

x = ["Jan", "Feb", "March", "April"]


y = [2, 6, 3, 1]

[Link](x, y)
[Link]("Months")
[Link]("Values")
[Link]("Bar Plot")

[Link]()

In [3]: import [Link] as plt

x = [0, 1, 2, 3, 4]
y = []

for i in x:
cube = i ** 3
[Link](cube)

print(y)

[Link](x, y)
[Link]("x")
[Link]("y")
[Link]("x and its cubes")

[Link]()

[0, 1, 8, 27, 64]

In [6]: import [Link] as plt

data = [1,2,2,3,3,3,4,4,4,4,5,5,6]

[Link](data)
[Link]("Values")
[Link]("Frequency")
[Link]("Histogram")

[Link]()
In [ ]:
In [1]: num = 10

if num > 0:
print("Positive number")
else:
print("Negative number or zero")

Positive number

In [2]: for i in range(1, 6):


print(i)

1
2
3
4
5

In [3]: i = 1

while i <= 5:
print(i)
i += 1

1
2
3
4
5

In [4]: n = 10
a, b = 0, 1

for i in range(n):
print(a)
a, b = b, a + b

0
1
1
2
3
5
8
13
21
34

In [5]: num = 5
fact = 1

for i in range(1, num + 1):


fact *= i

print("Factorial:", fact)
Factorial: 120

In [6]: def factorial(n):


if n == 0 or n == 1:
return 1
return n * factorial(n - 1)

print(factorial(5))

120

In [7]: num = 7

if num % 2 == 0:
print("Even")
else:
print("Odd")

Odd

In [8]: marks = 75

if marks >= 90:


print("Grade A")
elif marks >= 70:
print("Grade B")
elif marks >= 50:
print("Grade C")
else:
print("Fail")

Grade B

In [9]: total = 0

for i in range(1, 6):


total += i

print("Sum:", total)

Sum: 15

In [ ]: num = 5

for i in range(1, 11):


print(num, "x", i, "=", num * i)
In [1]: import [Link] as plt

x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]

[Link](x, y)
[Link]("Line Graph")
[Link]("X-axis")
[Link]("Y-axis")

[Link]()

In [2]: import [Link] as plt

subjects = ["Math", "Science", "English"]


marks = [80, 70, 90]

[Link](subjects, marks)
[Link]("Bar Graph")

[Link]()
In [3]: import [Link] as plt

labels = ["A", "B", "C"]


sizes = [40, 35, 25]

[Link](sizes, labels=labels, autopct='%1.1f%%')


[Link]("Pie Chart")

[Link]()
In [4]: import [Link] as plt

x = [1, 2, 3, 4, 5]
y = [5, 7, 6, 8, 7]

[Link](x, y)
[Link]("Scatter Plot")

[Link]()
In [ ]:

You might also like