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

Ash Prac New

The document contains a series of practical programming exercises primarily focused on Python, including tasks such as printing 'Hello World', using arithmetic and logical operators, and implementing various functions. Each practical includes a question, code, and output, demonstrating fundamental programming concepts and techniques. Additionally, it provides installation instructions for Python and covers string manipulation, mathematical functions, and recursion.

Uploaded by

alhaddadruhaan
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)
14 views36 pages

Ash Prac New

The document contains a series of practical programming exercises primarily focused on Python, including tasks such as printing 'Hello World', using arithmetic and logical operators, and implementing various functions. Each practical includes a question, code, and output, demonstrating fundamental programming concepts and techniques. Additionally, it provides installation instructions for Python and covers string manipulation, mathematical functions, and recursion.

Uploaded by

alhaddadruhaan
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/ 36

SR EXAMINER

NO DATE NAME OF THE PRACTICAL SIGN

1 22/06/2023 Write a program to print “Hello World”

2 22/06/2023 Write a program using arithmetic


operators

3 22/06/2023 Write a program using logical operators

4 22/06/2023 Write a program using identity


operators

5 22/06/2023 Write a program to find out the largest


number among 2 numbers

6 22/06/2023 Write a program to display the following


series

7 23/06/2023 Write a program to display the following


series

8 23/06/2023 Program to use break statement


Installation
1. Visit www.python.org/downloads/

2. Click on Download “Python 3.11.4”

3. Click on Open File


4. Click on “Install Now”

5. To open Interactive Screen search “IDLE” in Start Menu


Practical no:1

QUESTION: Write a program to print (“hello world”)

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

QUESTION: Write a program to use logical operators.


CODE :
#ASHTON COELHO (157)
s=true
t=false
print('s and t is',s and t)
print ('s or t',s or t)
print('not s is'not s)
output:
PRACTICAL NO:4
QUESTION:Write a program using identity operators
CODE:
#ASHTON COELHO (157)
s1=4
s2=4
t1='pari'
t2='pari'
y1=[41,42,43]
y2=[41,42,43]
print("s1:",s1,"s2:",s2)
print("t1:",t1,"t2:",t2)
print("y1:",y1,"y2:",y2)
print("s1 is not s2",s1 ia not s2)
print("s1 is s2",s1 is s2)
print("t2 is t1",t2 is t1)
print("t2 is not t1",t2 is not t1)
#output:false because lists are mutable(change)
print("y1 ia y2",y1 is y2)
print("y1 is not y2",y1 is not y2)
Output:
Practical No. 5
Question:- Write a program to find out the largest number among 2 numbers.
Code:-
# ASHTON COELHO (157)
s=4
t=4
print("s:", s, "t:", t)

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)

n = int(input("Enter any number: "))


a = sq1(n)
print(a)
Output:-
PRACTICAL NO. 15
Question:- Program to use of Boolean function
Code:-
# Ashton Coelho (157)
def xyz(s, t):
if s%t == 0:
result = True
else:
result = False
return result

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

Question:-program to use in and not in operator string


Code:-
#ASHTON COELHO (157)
st="Ashton"
print("st:",st)
print("V in st:" 'V' in st)
print("V not in st : ",'V' not in st)

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:-

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