Ash Prac New
Ash Prac New
Code:
#ASHTON COELHO (157)
Print (“hello world”)
Output:
Practical no:2
QUESTION: Write a program using arithmetic operators
Code:
#ASHTON COELHO (157)
s=4
t=6
print("s+t is",s+t)
print("s-t"is,s-t)
output:
PRACTICAL NO:3
if s > t:
print("s is greater than t")
elif t > s:
print("t is greater than s")
else:
print("s is equal to t")
Output:-
Practical No. 6
Question:- Write a program to display the following series:-
1
22
333
4444
55555
Code:-
# ASHTON COELHO (157)
i=1
while i <= 5:
j=1
while j <= i:
print(i, end="")
j=j+1
i=i+1
print(" ")
Output:-
Practical No. 7
Question:- Write a program to display the following series:-
*
**
***
****
*****
Code:-
# ASHTON COELHO (157)
for i in range(6):
for i in range(i):
print("*", end="")
print("")
Output:-
Practical No. 8
Question:- Program to use break statement
Code:-
# ASHTON COELHO (157)
n = (1, 2, 3, 4, 5)
for i in n:
print(i)
if i==3:
break
Output:-
Practical No. 9
Question:- write a program to use math function
Code:-
# ASHTON COELHO (157)
import math
print("math.sqrt(4):",math.sqrt(4))
print("math.pi:"math.pi)
print("math.ceil(5.1): ",math.ceil(5.1))
print("math.floor(5.1): ",math.floor(5.1))
print("math.exp(3.0):",math.exp(3.0))
print("math.log(2.0):",math.log(3))
print("math.log10(2.0): ",math.log10(2))
print("math.pow(2,3):",math.pow(2,3))
print("math.sin(0):",math.sin(90))
print("math.cos(0): ",math.cos(45))
print("math.tan(45):",math.tan(0))
output:-
Practical No. 10
Question:- Program to find maximum number among two numbers.
Code:-
#ASHTON COELHO (157)
def FnMax(s,t):
if s>t:
print(s,"is maximum")
elif s == t:
print(s, "is equsl to", t)
else:
print(t,"is maximum")
FnMax(11, 27)
Output:-
PRACTICAL NO. 11
Question:- Program to find average of three numbers
Code:-
# ASHTON COELHO (157)
def avrg(n1,n2,n3):
sum=n1+n2+n3
avg=sum/3
print(avg)
avrg(11,27,8)
avrg(4,8,2)
Output:-
PRACTICAL NO. 12
Question:- Program for default arguments in function
Code:-
# Ashton Coelho (157)
def demo(s, t=5, v=10):
print("s:", s, "t:", t, "v:", v)
demo(3, 7)
demo(2)
demo(27, 11, 8)
Output:-
PRACTICAL NO. 13
Question:- Program to calculate area of a circle
Code:-
# Ashton Coelho (157)
def area(r):
return(3.14*r*r)
a = area(2)
print(a)
Output:-
PRACTICAL NO. 14
Question:- Program to calculate square of a number
Code:-
# Ashton Coelho (157)
def sq1(s):
return(s*s)
print(xyz(4, 2))
Output:-
PRACTICAL NO. 16
Question:- Program to find area of a triangle
Code:-
# Ashton Coelho (157)
def area(b, h):
return(1/2*b*h)
a = area(5, 10)
print(a)
output:-
PRACTICAL NO. 17
Question:- Program to find factorial of a number
Code:-
# Ashton Coelho (157)
def fact(n):
if n == 0:
return 1
else:
return n * fact(n-1)
print(fact(0))
print(fact(3))
Output:-
PRACTICAL NO. 18
Question:- Program to print Fibonacci series using recursive function
Code:-
# Ashton Coelho (157)
def fib(n):
if n <= 1:
return n
else:
return(fib(n-1) + fib(n-2))
nt = 4
for i in range(nt):
print(fib(i))
Output:-
PRACTICAL NO. 19
Question:- write a program to transversal string using for loop
Code:-
# Ashton coelho (157)
st="Ashton coelho"
i=0
for i in st:
print(i)
Output:-
PRACTICAL NO. 20
Question:-program to transversal string using while loop
Code:-
# Ashton coelho (157)
st="Ashton coelho"
i=0
while i < len(st):
a=st[i]
print(a)
i=i+1
Output:-
PRACTICAL NO. 21
Question:- Program to use slice operator in string
Code:-
#Ashton coelho (157)
st="Ashton coelho"
print(st)
for i in st:
print(st.index(i),i)
print("st[:5]",st[6:])
print("st[3:]",st[3:])
print("st[2:4]",st[2:4])
Output:-
PRACTICAL NO. 22
Question:- program to use of find function of string
Code:-
#ASHTON COELHO (157)
st="Ashton coelho"
print(st)
print("st.find('e')",st.find('e'))
print("st.find('e',4)",st.find('e',7))
print("st.find('e',2,4)",st.find('e',2,4))
Output:-
PRACTICAL NO. 23
Question:- program to search specific position of character in string
Code:-
# ASHTON COELHO (157)
def find(st,a):
i=0
while i< len(st):
if st[i] == a:
return i
i = i+1
return -1
print(find("ASHTON",'S'))
Output:-
PRACTICAL NO. 24
Question:-program to demonstrate use of different string functions.
Code:-
#ASHTON COELHO (157)
St="hello world"
St1="Ashton"
St2="Coelho"
St3="Ashton Coelho"
print("st:",st:,"st1:",st1,"st2:",st2)
print("st1+st2=",st1+st2)
print("st2*2=",st1*3)
print("st1.swapcase():",st1.swapcase())
print("st.split():",st.split())
print("st1.rfind(st3):",st1.rfind(st3))
print("st1.find(st3):",st1.find(st3))
print("max(st2):"+max(st2))
print("min(st2):"+min(st2))
print("st2.lower():",st1.lower())
print("st2.upper():",st2.upper())
print("st.isalpha():",st.isalpha())
print("st.idigit():",st.isdigit())
print("st.capatalize():",st.capatalize())
print("length of the string:",len(st))
print("st.replace('i','a'):",st.replace('i','a'))
Output:-
Practical no. 25
Output:-
Practical no. 26
Question:-program to compare string
Code:-
#ASHTON COELHO(157)
st1="Ashton"
st2="Coelho"
st3="Ashton"
st4="Coelho"
print("st1:",st1)
print("st2:",st2)
print("st3:",st3)
print("st4:",st4)
print("st1==st3:",st1==st3)
print("st2==st4:",st2==st4)
print("st2<st4:",st2<st4)
print("st2<st1:",st2<st2)
Output:-
Practical no.27
Question:- program to string palindrome
Code:-
#ASHTON COELHO (157)
st1="madam"
st2=st1[::-1]
if st1==st2:
print("String is palindrome")
else:
print("string is not palindrome")
Output:-