0% found this document useful (0 votes)
61 views12 pages

Python All

The document contains a collection of Python code snippets demonstrating various programming concepts, including conversions between units, calculations for geometric shapes, number classification, list and tuple operations, set manipulations, dictionary handling, and exception management. Each section provides a specific functionality, such as calculating surface area, checking for palindromes, generating random numbers, and implementing classes with inheritance. The snippets serve as practical examples for learning Python programming.

Uploaded by

Shubham Urane
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)
61 views12 pages

Python All

The document contains a collection of Python code snippets demonstrating various programming concepts, including conversions between units, calculations for geometric shapes, number classification, list and tuple operations, set manipulations, dictionary handling, and exception management. Each section provides a specific functionality, such as calculating surface area, checking for palindromes, generating random numbers, and implementing classes with inheritance. The snippets serve as practical examples for learning Python programming.

Uploaded by

Shubham Urane
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

PYTHON INTERNAL

[Link] bits to MB,GB and TB

Bits = int(input(“enter bits : ”))

Byte= Bits/8

Kb= Byte/1024

Mb= Kb/1024

Gb= Mb/1024

Tb= Gb/1024

print(Bits, “bits is ”,Mb, “MB”)

print(Bits, “bits is ”,Gb, “GB”)

print(Bits, “bits is ”,Tb, “TB”)

[Link] area

print("Enter the height=")

len1=int(input())

print("Enter the radius=")

red1=int(input())

area=2*3.14*red1*len1+2*3.14*red1*red1

volume=3.14*red1*red1*len1

print("SurfaceArea of Cylinder",area)

print("Volume of Cylinder",volume)

[Link] And Negative

print("Enter the Number=")

num=int(input())

if num==0 :

print("Number is zero")

elif num>0 :

print("Number is positive")
else:

print("Number is negative")

[Link]

print("Enter the 5 subject marks :")

m1=int(input())

m2=int(input())

m3=int(input())

m4=int(input())

m5=int(input())

total=m1+m2+m3+m4+m5

per=(total/100)*100

if per>=75 and per<=100 :

print("A grade")

elif per>=60 and per<=75 :

print("B grade")

elif per>=40 and per<=60 :

print("C grade")

else:

print("Fail")

[Link]

print("Enter the number=")

num=int(input())

a=0

b=1

print(a)

print(b)

i=3

while i<=num:

c=a+b
print(c)

a,b=b,c

i=i+1

[Link]

print("Enter the number=")

num=int(input())

rev=0

tem=num

while num>0:

rem=num%10

rev=(rev*10)+rem

num=num//10

if rev==tem:

print("It is palindrome")

else:

print("It is not palindrome")

[Link] from list

list1 = [10, 20, 38, 2, 4]

[Link]()

print("Sorted array")

print(list1)

print("Largest number")

print(list1[-1])

8. even from a list

list1 = [10, 20, 38, 2, 4,77,89]

for i in list1:

if i%2==0 :
print(i)

[Link] from tuple

tuple1=(10,2,3,4,5,67)

print("MAX==",max(tuple1))

print("MIN==",min(tuple1))

10. repeated from list

tuple1=(10,20,39,20,39,67,10)

#print([Link](10))

i=0

a=tuple1.__len__()

while i<a :

j=i+1

while j<a :

if tuple1[i]==tuple1[j]:

print(tuple1[i])

j=j+1

i=i+1

11. intersection

set1={10,20,30,40,}

set2={50,60,40}

set3=[Link](set2)

set4=[Link](set2)

set5=[Link](set2)

set6=set1.symmetric_difference(set2)

print(set3)

print(set4)

print(set5)
print(set6)

[Link]()

print(set1)

12. add and remove

set1={ 10,20,30,40}

[Link](50)

print(set1)

13 .max and min from set

set1={10,20,30,40,}

print(“MAX==”,max(set1))

print(“MIN==”,min(set1))

[Link] sort

my_dict = { 1:30, 4:60, 2:40, 3:30 }

print(sorted(my_dict.items())

ascending_dict = dict(sorted(my_dict.items(), key = lambda item:item[1]))

descending_dict = dict(sorted(my_dict.items(), key = lambda item:item[1], reverse=True))

print(ascending_dict)

print(descending_dict)

[Link] concatenation

dict1 = {1:10, 2:20}

dict2 = {3:30, 4:40}

dict3 = {}

[Link](dict1)

[Link](dict2)

print(dict3)
[Link] fun

def strcheck(str1):

lc = 0

uc = 0

for i in str:

if [Link]():

lc += 1

elif [Link]():

uc += 1

else:

pass

print("No of lower case letter in string", lc)

print("No of Upper case letter in string", uc)

str = input("ENTER THE STRING:")

strcheck(str)

17. prime function

def primeno(no):

count=0

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

if no % i==0:

count+=1

if count==2:

print(no,"Is prime number")

else:

print(no, "is not prime")

num=int(input("Enter The NO"))

primeno(num)
18. collage user defined

#clg

def college():

name = input("Enter the name of collage:")

print(name)

#demo

import clg

[Link]()

19. calender

import calendar as c

y=int(input("Enter the year:"))

m=int(input("Enter the month:"))

print([Link](y,m))

[Link] using built in fuction

import math

r=int(input("Enter the radius="))

print("area=",[Link]*r*r)

print("circumference=",2*[Link]*r)

[Link] add

import numpy as np

mat1=[Link]('123;456')

mat2=[Link]('123;456')

sum1=[Link](mat1,mat2)

print(sum1)

sub=[Link](mat1,mat2)

print(sub)

mul=[Link](mat1,mat2)

print(mul)
div=[Link](mat1,mat2)

print(div)

[Link] ( area of square)

class Area:

def cal(self ,a=None,b=None):

if(a!=None and b!=None):

print("Area of rectangle=",a*b)

else:

print("Area of Squre=",a * a)

obj=Area()

[Link](10,20)

[Link](10)

[Link]

from symtable import Class

class Degree:

def getDegree(self):

print("I got degree")

class Undergraduate(Degree):

def getDegree(self):

print("I am Undergraduate")

class post_graduate(Undergraduate):

def getDegree(self):

print("post_graduate")

obj=Degree()

[Link]()

obj1=Undergraduate()

[Link]()

obj2=post_graduate()
[Link]()

24 employee

class Employee:

def get(self):

[Link] = input("Enter name: ")

[Link] = int(input("Enter Employee ID: "))

[Link] = input("Enter Address: ")

def put(self):

print("\nEmployee Details:")

print("NAME:", [Link])

print("EMPLOYEE ID:", [Link])

print("ADDRESS:", [Link])

# Creating an instance and testing the methods

ob = Employee()

[Link]()

[Link]()

[Link] inheritance

class A:

def fun1(self):

print(“Function 1 is called…”)

class B:

def fun2(self):
print(“Function 2 is called….”)

class C:

def fun3(self):
print(“Function 3 is called….”)

c1=new C()

c1.fun1()
c1.fun2()

c1.fun3()

26. ZeroDivisorError Exception

try:

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

b=int(input("Enter number: "))

div=a/b

print("Division is",div)

except ZeroDivisionError:

print("Can't divide by 0")

27. six random integer

import numpy as np

# Generate 6 random integers between 10 and 30 (inclusive of 10, exclusive of 30)

random_integers = [Link](10, 31, size=6)

print("Random integers:", random_integers)

28. password check

class wrongData(Exception):

pass

try:

password="Abc@123"

userid=input("Enter userid: ")

pw=input("Enter password: ")

if(password==pw):

print("Login successful...")
else:

raise wrongData

except wrongData:

print("Wrong Password!")

29. random float

import random

# Generate a random float between 5 and 50

random_float = [Link](5, 50)

print("Random float between 5 and 50:", random_float)

30. factorial using function

def fact(num):

if num < 0:

print("Factorial is not defined for negative numbers.")

return

factorial1 = 1

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

factorial1 *= i

print("Factorial of", num, "=", factorial1)

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

fact(num1)

31. even number

i=1

while i<100 :

if i%2==0 :
print(i)

i=i+1

32. reverse

print("Enter the number=")

num=int(input())

rev=0

while(num>0):

rem=num%10

rev=(rev*10)+rem

num=num//10

print("revers=",rev)

You might also like