0% found this document useful (0 votes)
3 views25 pages

manmeet

The document contains multiple Python programs that demonstrate various functionalities including checking for Armstrong numbers, leap years, list and tuple operations, stack operations, profit and loss calculations, and employee salary input using tuples. Each program is presented with input prompts and outputs relevant results based on user input. The document serves as a comprehensive guide for beginners to understand basic programming concepts in Python.

Uploaded by

samralakhdeep
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)
3 views25 pages

manmeet

The document contains multiple Python programs that demonstrate various functionalities including checking for Armstrong numbers, leap years, list and tuple operations, stack operations, profit and loss calculations, and employee salary input using tuples. Each program is presented with input prompts and outputs relevant results based on user input. The document serves as a comprehensive guide for beginners to understand basic programming concepts in Python.

Uploaded by

samralakhdeep
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/ 25

#write a program in python to check whether the number is armstrong number or not.

n=int(input(" enter the number :"))

s=0

temp=n

while temp>0:

digit=temp%10

s+=digit**3

temp//=10

if n==s:

print(n," is an armstrong number ")

else:

print(n," is not \an armstrong number ")


#write a program in python to check if a year is leap year or not.

year=int(input(" enter a year :"))

if(year%4)==0:

if(year%100)==0:

if(year%400)==0:

print("leap year")

else:

print(" not a leap year")

else:

print("leap year")

else:

print(" not a leap year")


# write a program in python to perform list functions.

t=[5,6,8,7]

print(t[2]) #indexing

print(t[-3:-1]) #accessing

print(t[1:2]) #slicing

a=[1,2,3,4,5]

b=[4,3,2,1,6]

c=a+b

print(" addition of a and b is :") #concatenation

marks=[6,6,7]

print(marks*4) #repetition

m=["summer","winter","monsoon"] #membership

print('winter' in m)

print('monsoon' not in m)

s=["bread","butter","sandwich"] #treaversing

for i in range(len(s)):

print(s[i])
\
# write a program in python to perform tuple built in functions.

t=(33,6,7,44)

print(len(t)) #len

item=tuple()

print(item) #tuple

s=(1,4,6,4,8,4,)

print(s.count(4)) #count

print(s.index(8)) #index

print(max(s)) #max

print(min(s)) #min

print(sum(s)) #sum

print(sorted(s)) #sorted
# write a program in python to create a tuple from a list.

l=[1,2,3,4,'two']

print("\ntuple using list :")

print(tuple(l))

# write a program to create a tuple from a string.

t=tuple('one')

print("\ntuple with use of function :")

print(t)

# write a program in python to change the value of third last item from 5 to 5.5.

t=(10,2,3,4,5,2,6)

print(" original tuple is :",t)

s=list(t)

s[-3]=5.5

t=tuple(s)

print("updated tuple is :",t)


# write a program in python to perform stack.

stack=[]

stack.append('element 1 ')

stack.append('element 2 ')

stack.append('element 3 ')

print(' initial stack ')

print(stack)

print('\nelements poped out from stack:')

print(stack.pop())

print(stack.pop())

print('\nstack after elements are popped out :')

print(stack)
# write a program in python to perform stack.

stack=[]

stack.append('element 1 ')

stack.append('element 2 ')

stack.append('element 3 ')

print(' initial stack ')

print(stack)

print('\nelements poped out from stack:')

print(stack.pop())

print(stack.pop())

print(stack.pop())

print('\nstack after elements are popped out :')

print(stack)

# write a program in python to perform stack operation.

host=[ ]

ch='y'

def push(host):

hn=int(input(" enter hostel number :"))

ts=int(input(" enter total students :"))

tr=int(input(" enter total rooms :"))

temp=[hn,ts,tr]
host.append(temp)

def pop(host):

if(host==[ ]):

print(" no record ")

else:

print(" deleted record is :",host.pop())

def display(host):

l=len(host)

print(" hostel number\ttotal students\ttotal rooms")

for i in range(1-1,-1,-1):

print(host[i][0],"\t\t",host[i][1],"\t\t",host[i][2])

while(ch=='y' or ch=='Y'):

print("1.add record\n")

print("2.delete record\n")

print("3.display record\n")

print("4.exit")

op=int(input(" enter the choice "))

if(op==1):

push(host)

elif(op==2):

pop(host)

elif(op==3):

display(host)

elif(op==4):

break
ch=input(" do you want to remove more(Y/N)?")
# write a program in python to calculate profit and loss.

actual_cost=float(input(" enter actual product price:"))

sale_amount=float(input(" enter sales amount:"))

if(actual_cost>sale_amount):

amount=actual_cost-sale_amount

print(" total loss amount={0}".format(amount))

elif(sale_amount>actual_cost):

amount=sale_amount-actual_cost

print(" total profit={0}".format(amount))

else:

print(" no profit no loss!!!")


# write a number in python to check it is divisible by 5 or 11 or not.

n=int(input(" enter any positive integer :"))

if((n%5==0)and(n%11==0)):

print(" given number is divisible by 5 and 11")

else:

print("given number is not divisible by 5 and 11")


u=int(input(" enter number of units :"))

if(u<50):

a=units*2.60

s=25

elif(u<=100):

a=130+((u-50)*3.25)

s=35

elif(u<=200):

a=130+162.50+((u-100)*5.26)

s=45

else:

a=130+162.5+526+((u-200)*8.45)

s=75

total=a+s

print("\nelectricity bill=%.2f"%total)
# write a program in python to find a strong number.

number=int(input(" enter any number:"))

sum=0

temp=number

while(temp>0):

factorial=1

i=1

reminder=temp%10

while(i<=reminder):

factorial=factorial*i

i=i+1

print("\nfactorial of %d=%d" %(reminder,factorial))

sum=sum+factorial

temp=temp//10

print("\n sum of factorials of a given number %d=%d"%(number,sum))

if(sum==number):

print("%d is a strong number"%number)

else:

print("%d is not a strong number "%number)


# write a program in python to input the salary of n number of employes using a tuple.

t=tuple( )

n=eval(input("enter the number of employees :"))

for i in range(n):

a=eval(input(" enter salary of employee :"))

t=t+ (a, )

print(" maximum salary =",max(t))

print(" minimum salary =",min(t))


#write a program in python to print factorial of a number.

n=eval(input(" enter a factorial of a number :"))

f=1

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

f=f*i

print("n=",f)
# write a program in python to print grades

english=float(input("enter english marks:"))

maths=float(input("enter maths marks:"))

computer=float(input("enter computer marks:"))

physics=float(input("enter physics marks:"))

chemistry=float(input("enter chemistry marks:"))

total=english+maths+computer+physics+chemistry

percentage=(total/500)*100

print("total marks=%.2f"%total)

print("marks percentage=%.2f"%percentage)

if(percentage>=90):

print(" a grade ")

elif(percentage>=80):

print(" b grade ")

elif(percentage>=70):

print(" c grade ")

elif(percentage>=60):

print(" d grade ")

elif(percentage>=40):

print(" e grade ")

else:

print("fail")

You might also like