0% found this document useful (0 votes)
19 views23 pages

122a9030 Exp1 SBL B2

python expirement

Uploaded by

neeraj patil
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)
19 views23 pages

122a9030 Exp1 SBL B2

python expirement

Uploaded by

neeraj patil
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/ 23

NAME: Pavan Santosh Dhadge

PRN NO: 122A9030


EXPERIMENT 1
Q.1) Write a prgram to input the side of a square and print area and
perimeter of square.
PROGRAM AND OUTPUT:

s=int(input("ENTER SIDE OF SQUARE:"))


area=s*s
perimeter=4*s
print("AREA OF SQUARE:",area)
print("PERIMETER OF SQUARE:",perimeter)

Q.2) Accept Product Code (Pc), Quantity (Qty) and Price of product
(Pr). Calculate total cost of the product, 12.5% discount on total cost and
net price to be paid after discount.
PROGRAM AND OUTPUT:

pc=int(input("ENTER PRODUCT CODE:"))


qty=int(input("ENTER NUMBER OF QUANTITY:"))
pr=int(input("ENTER PRICE OF PRODUCT:"))
print("TOTAL COST OF PRODUCT BEFOR DISCOUNT:",pr)
dis=(12.5/100)*pr
prr=pr-dis
print("TOTAL COST OF PRODUCT AFTER DISCOUNT:",prr)
print("TOTAL PRICE TO BE PAID AFTER DISCOUNT:",prr)

Q.3) To convert temperature from Fahrenheit to Celsius and Celsius to


Fahrenheit
PROGRAM AND OUTPUT:

c=int(input("ENTER TEMPERATURE IN CELCIUS:"))


f=int(input("ENTER TEMPERATURE IN FAHRENHEIT:"))
cel=(f-32)*(5/9)
fah=c*(9/5)+32
print("TEMPERATURE IN FAHRENHEIT :",fah)
print("TEMPERATURE IN CELCIUS :",cel)

Q.4) Add,subtract, multiply and divide two complex number


PROGRAM AND OUTPUT:
a=int(input("ENTER NUMBER 1:"))
b=int(input("ENTER NUMBER 2:"))
c=int(input("ENTER NUMBER 3:"))
d=int(input("ENTER NUMBER 4:"))
com=complex(a,b)
com1=complex(c,d)
add=com+com1
sub=com-com1
mul=com*com1
div=com/com1
print("ADDITION IS:",add)
print("MULTIPLICATION IS :",mul)
print("DIVISION IS:",div)
print("SUBTRACTION IS:",sub)
Q.5)

PROGRAM AND OUTPUT:


y=int(input("ENTER CONSUMER NUMBER:"))

z=input("ENTER NAME OF CONSUMER:")

n=int(input("ENTER NUMBER OF UNIT OF ELECTRICITY CONSUMED:"))

if(n>=199):

c=n*1.20

print("AMOUNT OF BILL TO BE PAID:",c)

elif(n>=200 or n<400):

c=n*1.50

print("AMOUNT OF BILL TO BE PAID:",c)

elif(n>=400 or n<600):

c=n*1.80

print("AMOUNT OF BILL TO BE PAID:",c)

else:

c=n*2.00

print("AMOUNT OF BILL TO BE PAID:",c)

if(c>400):

print("CONSUMBER NUMBER:",y)

print("NAME OF CUSTOMER:",z)
k=(15/100)*c

print("TOTAL AMOUNT OF BILL TO BE PAID:",c+k)

elif(c>100 or c>200 or c>300):

print("CONSUMBER NUMBER:",y)

print("NAME OF CUSTOMER:",z)

print("TOTAL AMOUNT OF BILL TO BE PAID:",c)

else:

print("CONSUMBER NUMBER:",y)

print("NAME OF CUSTOMER:",z)
print("TOTAL AMOUNT OF BILL TO BE PAID:100")
Q.6)

PROGRAM AND OUTPUT:


t=int(input("ENTER TEMPERATURE:"))
if(t<0):

print("FREEZING WEATHER")

elif(t==0 or t<10):

print("VERY COLD WEATHER")

elif(t==10 or t<20):

print("COLD WEATHER")

elif(t==20 or t<30):

print("NORMAL TEMPERATURE")

elif(t==30 or t<40):

print("ITS HOT")
else:

print("ITS VERY HOT")


Q.7) A program to find sum of all prime numbers between 1 to n
PROGRAM AND OUTPUT:

def isprime(n):
if n<=1:
return False
for i in range(2,int(n**0.5)+1):
if n%i == 0:
return False
return True
def sumofprimes(num):
sum1=0
for i in range(2,num+1):
if isprime(i):
sum1=sum1+i
return sum1
num=int(input("ENTER NUMBER:"))
res=sumofprimes(num)
print("SUM OF PRIME NUMBERS:",res)

Q.8) A program to find all prime factors of a number.


PROGRAM AND OUTPUT:

def prime_factors(n):
factors = []
while n % 2 == 0:
factors.append(2)
n //= 2
for i in range(3, int(n**0.5) + 1, 2):
while n % i == 0:
factors.append(i)
n //= i
if n > 2:
factors.append(n)
return factors
num = int(input("Enter a number to find its prime factors: "))
print("Prime factors of", num, "are:", prime_factors(num))

Q.9) A program to check whether a number is Armstrong number or not.


PROGRAM AND OUTPUT:

def armstr(i):
x1=int(i)
n=int(i)
s=0
z=str(i)
l=len(z)
while(x1!=0):
s=s+pow((x1%10),l)
x1=x1//10
if(n!=s):
print(i,"is Not Armstrong.",end=' ')
elif(n==s):
print(i,"is Armstrong.",end=' ')
a=input("Enter The Value of N: ")
armstr(a)

Q.10) A program to print all Armstrong numbers between 1 to n


PROGRAM AND OUTPUT:

def ars(i,f):
x1=int(i)
n=int(i)
s=0
z=str(i)
l=len(z)
while(x1!=0):
s=s+pow((x1%10),l)
x1=x1//10
if(n!=s):
pass
elif(n==s):
f.append(i)
a=input("Enter The range of N: ")
f=[]
for j in range(1,int(a)+1):
ars(j,f)
for j in f:
print(j,end=',')
print("are the Armstrong Numbers upto",a,".")
Q.11) A program to check whether a number is Perfect number or not.
PROGRAM AND OUTPUT:

a=input("enter N value:")
x=a
s=0
f=[]
for j in range(1,int(a)):
if((int(x)%j)==0):
f.append(j)
z=len(f)
for i in range(0,z):
s=s+f[i]
if(int(s)==int(x)):
print(x,"is a Perfect Number.")
else:
print(x,"is not a Perfect Number.")

Q.12) A program to print all Perfect numbers between 1 to n.


PROGRAM AND OUTPUT:

def prf(a,q):
x=a
s=0
f=[]
for j in range(1,int(a)):
if((int(x)%j)==0):
f.append(j)
z=len(f)
for i in range(0,z):
s=s+f[i]
if(int(s)==int(x)):
q.append(x)
else:
pass
a=input("enter N value:")
q=[]
for i in range(1,int(a)+1):
prf(i,q)
print(q,"are the Perfect Numbers upto",a,".")
Q.13) A program to check whether a number is Strong number or not.
PROGRAM AND OUTPUT:

import math
def srn(i):
x=int(i)
a=i
s=0
while(x!=0):
z=x%10
s=s+math.factorial(z)
x=x//10
if(int(a)==int(s)):
print(a,"is Strong Number.")
Q.14) A program to print all Strong numbers between 1 to n.
PROGRAM AND OUTPUT:

import math
def srn(i,q):
x=int(i)
a=i
s=0
while(x!=0):
z=x%10
s=s+math.factorial(z)
x=x//10
if(int(a)==int(s)):
q.append(i)
else:
pass
n=input("Enter The range of n: ")
q=[]
for i in range(1,int(n)+1):
srn(i,q)
print(q,"are the strong numbers upto",n)
else:
print(a,"is not a Strong Number.")
n=input("Enter The value of n: ")
srn(n)

Q.15) PATTERN 1
PROGRAM AND OUTPUT:

n=int(input("Enter The Value of N which is no. of lines of pattern


required: "))
for i in range(1,n+1,1):
if((i%2)!=0):
x=1
j=i
while(j!=0):
print(x,end='')
x=x+2
j=j-1
print()
elif((i%2)==0):
x=2
j=i
while(j!=0):
print(x,end='')
x=x+2
j=j-1
print()
Q.16) PATTERN 2
PROGRAM AND OUTPUT:

n=int(input("Enter n to print pattern: "))


for i in range(n,0,-1):
x=i
while(x!=0):
print(x,end='')
x=x-1
print()

Q.17) PATTERN 3
PROGRAM AND OUTPUT:

n=int(input("Enter n to print pattern: "))


for i in range(n,0,-1):
x=i
while(x!=0):
print('*',end='')
x=x-1
print()

Q.18) PATTERN 4
PROGRAM AND OUTPUT:

n=int(input("Enter n to print pattern: "))


for i in range(0,n):
x=0
while(x!=(i+1)):
print('*',end='')
x=x+1
print()
Q.19) PATTERN 5
PROGRAM AND OUTPUT:

n=int(input("ENTER VALUE:"))
for i in range(1,n+1,1):
if (i%2==0):
print(n*"0")
else:
print(n*"1")

Q.20) PATTERN 6
PROGRAM AND OUTPUT:

n=int(input("Enter The N Value:"))


j=n
while (j!=0):
x=n
if((x-j)==0):
print(x*str(x))
else :
for z in range(x,j,-1):
print(z,end='')
print(j*str(j))
j=j-1

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy