Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
5 views2 pages

Aish 1

The document contains various Python code snippets demonstrating data types, variable assignments, and operations such as arithmetic, logical, and relational operations. It also includes examples of functions for calculating square roots, areas of shapes, and checking for even or odd numbers. Additionally, it showcases the use of loops, conditionals, and built-in functions for tasks like finding maximum values and calculating factorials.

Uploaded by

aishwaryaade71
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)
5 views2 pages

Aish 1

The document contains various Python code snippets demonstrating data types, variable assignments, and operations such as arithmetic, logical, and relational operations. It also includes examples of functions for calculating square roots, areas of shapes, and checking for even or odd numbers. Additionally, it showcases the use of loops, conditionals, and built-in functions for tasks like finding maximum values and calculating factorials.

Uploaded by

aishwaryaade71
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/ 2

In [1]: a=5

print(a)

In [3]: type(a)

Out[3]: int

In [5]: b=3.14
print(b)

3.14

In [7]: type(b)

Out[7]: float

In [9]: name="aishwarya"
type(name)

Out[9]: str

In [11]: name='aishwarya'
type(name)

Out[11]: str

In [13]: L1=[10,20,30,40]
L2=["Apple","orange","banana","grapes"]

In [15]: print(L1)

[10, 20, 30, 40]

In [17]: print(L2)

['Apple', 'orange', 'banana', 'grapes']

In [19]: T1={1,2,3,4,5}
print(T1)

{1, 2, 3, 4, 5}

In [29]: T2=('Sun','Moon','Star')
print(T2)

('Sun', 'Moon', 'Star')

In [25]: set=(1,2,3,4,3,2)
print(set)

(1, 2, 3, 4, 3, 2)

In [27]: type(True)

Out[27]: bool

In [33]: dict={'A':'Mango','B':'Banana','C':'Cat'}
print(dict)

{'A': 'Mango', 'B': 'Banana', 'C': 'Cat'}

In [39]: x = None
type(x)

Out[39]: NoneType

In [41]: a=5
type(a)

Out[41]: int

In [43]: b=float(a)

In [45]: print(b)

5.0

In [47]: type(b)

Out[47]: float

In [55]: a="50"
b=int(a)
print(b+20)

70

In [53]: type(b)

Out[53]: int

In [123… del set

In [125… a=('Red','Blue','Yellow','Red')
b = set(a)
print(b)

{'Blue', 'Red', 'Yellow'}

In [75]: T1={1,2,3,4,5}
T2=list(T1)
print(T2)

[1, 2, 3, 4, 5]

In [77]: type(T2)

Out[77]: list

In [119… del dict

In [121… a=(('name','Aishwarya'),('age','21'))
b=dict(a)
print(b)

{'name': 'Aishwarya', 'age': '21'}

In [3]: a=5
b=6
print(id(a))

140729968048696

In [5]: print(id(b))

140729968048728

In [10]: a=[1,2,3]
b=[1,2,3]

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

1651541800896

In [14]: print(id(b))

1651541800192

In [16]: a is b

Out[16]: False

In [20]: a==b

Out[20]: True

In [26]: a=[1,2,3]
b=a
c=[1,2,3]

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

1651541813504

In [30]: print(id(b))

1651541813504

In [32]: print(id(c))

1651541804736

In [34]: print(a is b)
print(a is c)
print(a==c)
print(a is not c)

True
False
True
True

In [42]: #write python program to find square root of a number using exponential operator
n=int(input('Enter any number: '))
sqrt=n ** 0.5
print(sqrt)

5.0

In [48]: #write python program to swap two variables


a=10
b=20
print(a,b)
a,b=b,a
print(a,b)

10 20
20 10

In [53]: #write a program to find area of triangle


base=int(input('Enter base'))
height=int(input('Enter height'))
area=0.5*base*height
print(area)

25.0

In [1]: #logical operator


a=30
b=40
a&b

Out[1]: 8

In [3]: a or b

Out[3]: 30

In [5]: a^b

Out[5]: 54

In [7]: ~a

Out[7]: -31

In [9]: a<<b

Out[9]: 32985348833280

In [11]: a>>b

Out[11]: 0

In [15]: #Relational operators


a=30
b=60
print(a==b)
print(a!=b)
print(a>b)
print(a<b)
print(a>=b)
print(a<=b)

False
True
False
True
False
True

In [17]: #Identity Operators


a=[1,2,3]
b=a
c=[1,2,3]
print(a is b)
print(a is c)
print(a == c)
print(a is not c)

True
False
True
True

In [19]: # Write python program to find the square root of No using exponential operator
N= int(input("Enter the number"))
sqrt=N**0.5
print("square root of is ",sqrt)

square root of is 5.0

In [23]: #area of triangle


b= int(input("Enter the base"))
h= int(input("Enter the height"))
area= 0.5*b*h
print("Area of Triangle is",area)

Area of Triangle is 25.0

In [25]: #area of square


s=int(input("Enter the length of side :"))
area = s**2
print("Area of the square is :",area)

Area of the square is : 64

In [27]: # write the python program to check the Number is even or odd
N=int(input("Enter the Number"))
if N%2==0:
print(N,"is even")
else:
print(N,"is odd")

20 is even

In [29]: #write the python program to find the maximum of two Number
a= int(input("Enter First Number: "))
b= int(input("Enter second Number:"))
if a>b:
print("Maximum is:",a)
else:
print("maximum is :",b)

maximum is : 50

In [33]: # Maximum for 3 Number


a= int(input("Enter First Number: "))
b= int(input("Enter second Number:"))
c= int(input("Enter third number:"))
if a>=b and a>=c:
print("Maximum is:",a)
elif b>=a and b>=c:
print("Maximum is:",b)
else:
print("Maximum is:",c)

Maximum is: 41

In [35]: a= int(input("Enter First Number: "))


b= int(input("Enter second Number:"))
c= int(input("Enter third number:"))
print("Maximum is:",max(a,b,c))

Maximum is: 41

In [43]: # to find the Facctorial of Number


N=int(input("Enter the Number:"))
if N<0:
print("Factorial is not defined for negative Number:")
elif N==0:
print("Factorial of 0 to 1.")
else:
factorial=1
for i in range(1, N + 1):
factorial*=i
print("factorial of", factorial)

factorial of 120

In [45]: import math


N=int(input("Enter the Number:"))
print("Factorial is ",math.factorial(N))

Factorial is 120

In [47]: #to find Number is positive or negative


N=int(input("Enter the Number:"))
if N<0:
print("Number is negative:")
elif N>0:
print("Number is Positive:")
else:
print("Number is zero:")

Number is negative:

In [55]: #Write python program to convert Kilometer to meter


km=int(input("Enter distance in kilometers:"))
Meter=km*1000
print("Distance in meter:",Meter)

Distance in meter: 5000

In [1]: #python program to check whether a year is leap year


Y=int(input("Enter the year:"))
if(Y%4==0 and Y%100!=0):
print(Y,"is a leap year")
else:
print(Y,"is not leap year:")

2004 is a leap year

In [ ]: #Here's a simple Python program to find the sum of natural numbers up to a given number

In [23]: for letter in


"c,m,c,s,f,o,r,s,c,s".split(','):
if letter=='c' or letter=='s':
continue
print("current letter: ",letter)

Cell In[23], line 1


for letter in
^
SyntaxError: invalid syntax

In [27]: for letter in 'c,m,c,s,f,o,r,s,c,s'.split(','):


if letter=='c' or letter=='s':
continue
print("current letter: ",letter)

current letter: m
current letter: f
current letter: o
current letter: r

In [29]: c=float(input("Enter temperature in celsius: "))


f=(c*9/5)+32
print(f)

98.6

In [31]: n=[10,20,30,40,50]
sum1=sum(n)
print(sum1)

150

In [38]: a=[1,2,3,4,5,6,7,8]
product=1
for n in a:
product*=n

print(product)
40320

In [ ]:

You might also like