0% found this document useful (0 votes)
14 views6 pages

Program 1:: Output

Uploaded by

rajputaanya613
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
14 views6 pages

Program 1:: Output

Uploaded by

rajputaanya613
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 6

PROGRAM 1:

#Write a program to print palindrome from 1 to 100


number
d=0
rev=0
for i in range (1,101):
n=i
while n>0:
d=n%10
rev= rev*10+d
n= int( n/10)
if i== rev:
print (I ,end= ‘ ’)
rev=0

OUTPUT:
1 2 3 4 5 6 7 8 9 11 22 33 44 55 66 77 88 99
PROGRAM 3:
#write a program that checks
whether the tuple contain any
duplicate element or not
Tuplex=2,4,5,6,7,8,5,9,8,3,8
print (tuplex)
count=tuplex. count (8)
print ( count)

OUTPUT:
3
PROGRAM 5:
#write a program to implement simple calculator by
using function
def add ( a, b):
return a+ b
def subtract (a , b):
return a – b
def multiply (a ,b):
return a* b
def divide (a, b):
return a/ b
num1=float ( input (“enter first number”))
num2=float (input (“enter second number ”))

print (“operator:+,/,*,-”)
select=(input (“select operator ”))
if select==“+”:
print ( num 1,“+”, num 2,“=”,subtract( num 1,
num 2))
elif select=“*”:
print (num 1,“*”, num 2,“=” multiply number
1,num 2))
elif select ==“/”:
print ( num 1, “/”, num 2“=”, divide ( num 1, num
2))
else:
Print (“invalid input ”)

OUTPUT:
enter first number 4
enter second number 2
operator:+,/,*,-
select operation+
4.0+2.0=6.0
Process finished with exit code
PROGRAM 6:
#write a program to find the factorial of the
number by using function
def factorial (m):
fact =1
for i in range (1,m+ 1):
fact=fact*i
print (“factorial of”, m , “ is”, fact)
n = int ( input (“ enter a number:”))
factorial ( n )

OUTPUT:
Enter a number:5
Factorial of 5 is 120
Program 12:
#write the function of python to count the
number of line in a text file that are starting
with alphabet A.

def counline ():


file=open(‘ss.txt’ , ‘r’)
line=file.readlines()
c=0
for i in line:
if i [0]==‘A’ or i [0]==‘a’:
c=c+1
Print (“total number of line start with A:“,a”)
file.close()
Counline ()

OUTPUT:
Total number of line start with A:4
Process finished with exit code0

You might also like