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

Sameer Python File

The document contains Python programming lab exercises completed by Sameer Singh, a B.C.A student. It includes code snippets and outputs for various tasks such as checking for palindromes, Armstrong numbers, generating Fibonacci sequences, calculating factorials, and more. Each question is followed by the corresponding code and its output when executed.

Uploaded by

thapakartik021
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)
2 views12 pages

Sameer Python File

The document contains Python programming lab exercises completed by Sameer Singh, a B.C.A student. It includes code snippets and outputs for various tasks such as checking for palindromes, Armstrong numbers, generating Fibonacci sequences, calculating factorials, and more. Each question is followed by the corresponding code and its output when executed.

Uploaded by

thapakartik021
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/ 12

NAME : SAMEER SINGH COURSE : B.C.A ROLL NO.

: 69
UNIVERSITY ROLL NO. : 2221901 SEMESTER : 4th
SUBJECT : PYTHON PROGRAMMING LAB PBC : 401

QUES 1 :
CODE :
n=int(input("enteranumber:"))
temp=n
rev=0
while(n>0):
dig=n%10
rev=rev*10+dig
n=n//10
if(temp==rev):
print("numberispalindrome")
else:
print("not palindrome")

OUTPUT:

PS C:\Users\FRIEND>&
C:/Users/FRIEND/AppData/Local/Programs/Python/Python312/python.exe
c:/Users/FRIEND/Python/1st.py
enter a number:121
number is palindrome
PS C:\Users\FRIEND>&
C:/Users/FRIEND/AppData/Local/Programs/Python/Python312/python.exe
c:/Users/FRIEND/Python/1st.py
enter a number:345
not palindrome
PS C:\Users\FRIEND>
NAME : SAMEER SINGH COURSE : B.C.A ROLL NO. : 69
UNIVERSITY ROLL NO. : 2221901 SEMESTER : 4th
SUBJECT : PYTHON PROGRAMMING LAB PBC : 401

QUES 2 :

CODE :

a=int(input("Enteranumber:"))
sum = 0
temp =a
whiletemp >0:
dig=temp%10
sum+=dig**3
temp //= 10
if a ==
sum:print(a,"Armstrongnum
ber")
else:
print(a,"notArmstrongnumber")

OUTPUT:

PS C:\Users\FRIEND>&
C:/Users/FRIEND/AppData/Local/Programs/Python/Python312/python.exe
c:/Users/FRIEND/Python/pr.py
Enter a number: 153
153 Armstrong number
PS C:\Users\FRIEND>&
C:/Users/FRIEND/AppData/Local/Programs/Python/Python312/python.exe
c:/Users/FRIEND/Python/pr.py
Enter a number: 234
234 not Armstrong number
PS C:\Users\FRIEND>
NAME : SAMEER SINGH COURSE : B.C.A ROLL NO. : 69
UNIVERSITY ROLL NO. : 2221901 SEMESTER : 4th
SUBJECT : PYTHON PROGRAMMING LAB PBC : 401

QUES 4 :

CODE :

n=int(input("howmanyterms??:"))
n1=0
n2=1
count=0
if(n>0):
print("fibonaccisequence:")
while count<n:
print(n1)
n3=n1+n2
n1=n2
n2=n3
count+=1
elif(n<=0):
print("invalidno")

OUTPUT :

PS C:\Users\
FRIEND>&
C:/Users/FRIEND/App
Data/Local/Programs/P
ython/Python312/pytho
n.exe
NAME : SAMEER SINGH COURSE : B.C.A ROLL NO. : 69
UNIVERSITY ROLL NO. : 2221901 SEMESTER : 4th
SUBJECT : PYTHON PROGRAMMING LAB PBC : 401
c:/Users/FRIEND/Pyt
hon/pr.py
how many terms??:7
fibonacci sequence:
0
1
1
2
3
5
8
PS C:\Users\
FRIEND>
NAME : SAMEER SINGH COURSE : B.C.A ROLL NO. : 69
UNIVERSITY ROLL NO. : 2221901 SEMESTER : 4th
SUBJECT : PYTHON PROGRAMMING LAB PBC : 401
QUES 3 :

CODE :

n=int(input("enteranyno:"))
f=1
whilen>0:
f=f*n
n=n-1
print("factorialof anois:",f)

OUTPUT :

PS C:\Users\FRIEND>&
C:/Users/FRIEND/AppData/Local/Programs/Python/Python312/python.exe
c:/Users/FRIEND/Python/pr.py
enter any number:4
factorial of number is : 24
PS C:\Users\FRIEND>&
C:/Users/FRIEND/AppData/Local/Programs/Python/Python312/python.exe
c:/Users/FRIEND/Python/pr.py
enter any number:5
factorial of number is : 120
PS C:\Users\FRIEND>
NAME : SAMEER SINGH COURSE : B.C.A ROLL NO. : 69
UNIVERSITY ROLL NO. : 2221901 SEMESTER : 4th
SUBJECT : PYTHON PROGRAMMING LAB PBC : 401

QUES 5 :

CODE :

a=int(input("enteranumber:"))
sum=0
foriinrange(1,a):
if(a%i==0):
sum=sum+i
if(sum==a):
print("perfect")
else:
print("notperfect")

OUTPUT:

PS C:\Users\FRIEND>&
C:/Users/FRIEND/AppData/Local/Programs/Python/Python312/python.exe
c:/Users/FRIEND/Python/pr.py
enter a number:5
not perfect
PS C:\Users\FRIEND>&
C:/Users/FRIEND/AppData/Local/Programs/Python/Python312/python.exe
c:/Users/FRIEND/Python/pr.py
enter a number:6
perfect
PS C:\Users\FRIEND>
NAME : SAMEER SINGH COURSE : B.C.A ROLL NO. : 69
UNIVERSITY ROLL NO. : 2221901 SEMESTER : 4th
SUBJECT : PYTHON PROGRAMMING LAB PBC : 401

QUES 6 :

CODE :

a=input("enter a string:")
b=a.replace(" "," ")
print("stringafterusingtab:",b)

OUTPUT:

PS C:\Users\FRIEND>&
C:/Users/FRIEND/AppData/Local/Programs/Python/Python312/python.exe
c:/Users/FRIEND/Python/pr.py
enter a string:FRIEND GROUP
string after using tab: FRIEND GROUP
PS C:\Users\FRIEND>
NAME : SAMEER SINGH COURSE : B.C.A ROLL NO. : 69
UNIVERSITY ROLL NO. : 2221901 SEMESTER : 4th
SUBJECT : PYTHON PROGRAMMING LAB PBC : 401

QUES 7 :

CODE :

l=['3','4','7','9','2','3','6']
l1=l[-3:]
print("lastthreeelement:",l1)
l2=l[1:len(l)-1]
print("allvalueexceptfirstandlast:",l2) l3=l[0:3]
print("firstthreeelement:",l3)

OUTPUT:

PS C:\Users\FRIEND>&
C:/Users/FRIEND/AppData/Local/Programs/Python/Python312/python.exe
c:/Users/FRIEND/Python/pr.py
last three element: ['2', '3', '6']
all value except first and last: ['4', '7', '9', '2', '3']
first three element: ['3', '4', '7']
PS C:\Users\FRIEND>
NAME : SAMEER SINGH COURSE : B.C.A ROLL NO. : 69
UNIVERSITY ROLL NO. : 2221901 SEMESTER : 4th
SUBJECT : PYTHON PROGRAMMING LAB PBC : 401

QUES 8 :

CODE :

a=['5','8','9','4','8','9','7']
l=[]
fori in a:
if i not in l:
l.append(i)
print("listafterremovingduplicatevalue:",l)

OUTPUT:

PS C:\Users\FRIEND>&
C:/Users/FRIEND/AppData/Local/Programs/Py
thon/Python312/python.exe
c:/Users/FRIEND/Python/pr.py
list after removing duplicate value: ['5', '8', '9',
'4', '7']
PS C:\Users\FRIEND>
NAME : SAMEER SINGH COURSE : B.C.A ROLL NO. : 69
UNIVERSITY ROLL NO. : 2221901 SEMESTER : 4th
SUBJECT : PYTHON PROGRAMMING LAB PBC : 401

QUES 11 :

CODE :

a=input("enterastring:")
v=0
fori in a:
if(i=='a'ori=='e'ori=='i'ori=='o'ori=='u'):
v=v+1
print("vowelsare:",v)

OUTPUT:

PS C:\Users\FRIEND>&
C:/Users/FRIEND/AppData/Local/Programs/Python/Python312/python.exe
c:/Users/FRIEND/Python/pr.py
enter a string:FRIEND
vowels are: 2
PS C:\Users\FRIEND>
NAME : SAMEER SINGH COURSE : B.C.A ROLL NO. : 69
UNIVERSITY ROLL NO. : 2221901 SEMESTER : 4th
SUBJECT : PYTHON PROGRAMMING LAB PBC : 401

QUES 12 :

CODE :
quantity=int(input("entercostofiteam:"))
def purchase(quantity):
if(quantity>1000):cost=quantity-
(quantity*1/10)
print("discountcostis:",cost,"rs") else:
print("cost is:",quantity,"rs")
purchase(quantity)

OUTPUT:

PS C:\Users\Admin\OneDrive\Desktop\FRIEND> cd PYTHON
PS C:\Users\Admin\OneDrive\Desktop\FRIEND\PYTHON> python tempCodeRunnerFile.py
entercostofiteam:1500
discountcostis: 1350.0 rs
PS C:\Users\Admin\OneDrive\Desktop\FRIEND\PYTHON> python tempCodeRunnerFile.py
entercostofiteam:700
cost is: 700 rs
PS C:\Users\Admin\OneDrive\Desktop\FRIEND\PYTHON>
NAME : SAMEER SINGH COURSE : B.C.A ROLL NO. : 69
UNIVERSITY ROLL NO. : 2221901 SEMESTER : 4th
SUBJECT : PYTHON PROGRAMMING LAB PBC : 401

QUES 13 :

CODE :

year=int(input("enter the year of service:"))


salary=int(input("enteryourmonthysalary:")) def
bonus(salary,year):
if(year>5):
netbonus=salary*5/100
y=netbonus*12
print("permonthnetbonas:",netbonus,"rs") print("net
bonus of the year is:",y,"rs")
else:
print("nobonus:",salary,"rs")
bonus(salary,year)

OUTPUT:

PS C:\Users\Admin\OneDrive\Desktop\FRIEND\PYTHON> python tempCodeRunnerFile.py


enter the year of service:6
enteryourmonthysalary:50000
permonthnetbonas: 2500.0 rs
net bonus of the year is: 30000.0 rs
PS C:\Users\Admin\OneDrive\Desktop\FRIEND\PYTHON>

You might also like