0% found this document useful (0 votes)
5 views

Python Practical

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Python Practical

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Govt.

Polytechnic ,Manesar

Practicals

Name :Nishant Panchal


Roll No : 190070800031
Branch: Computer Engineering
Subject: Python

Submitted By Submitted To
Nishant Panchal Mrs.Reetu Mam
INDEX
So Name Date Remar
no ks
1. What do –lower,
count, replace.
String methods do?
2. Write instructions to
perform each of the steps
3. Write a program that
determines whether the
number is prime
4. Find all numbers which are
multiple of 17, but not the
multiple of 5, between 2000
and 2500
Swap two integer number
5.
using a temporary variable.
Repeat the exercise using
the code format: a, b=b, a.
Verify your results in both
the cases.
Find the largest of n
6. numbers, using a user
defined function largest().
Write a function
7. myReverse() Which receives
a string as an input and
returns the reverse of the
string. Check if a given
string is palindrome or not.
WAP to convert Celsius to
8. Fahrenheit
Find the ASCII value of
characters
9.
WAP for simple calculator

10.

Practical 1 :
What do the following string methods do?
 Lower
 Count
 Replace
a="Hello world"
print(a.lower())
print(a.count("e"))
print(a.replace("world",'everyone'))

Practical 2:
Write instructions to perform each of the steps below:
a.Create a string containing at least five words and
store it in a variable.
b.Print out the string.
c. Convert the string to a list of words using the string
split method.
d.Sort the list into reverse alphabetical order using
some of the list methods.
e.Print out the stored , reversed list of words.

a="apple,orange,mainsh,ghanshyam,ram"
print(a)
b=a.split(",")
print(b)
b.sort(reverse=True)
print(b)
Practical 3:
Write a program that determines whether the number is
prime
n=int(input('enter a number'))
r=2
while(r<n):
if(n%r)==0:
print(n,"is not a prime no")
break;
r=r+1
if(n==r):
print(n,"is a prime no")

Practical 4:
Find all numbers which are multiple of 17, but not the
multiple of 5, between 2000 and 2500
print("numbers multiple of 17, but not the multiple of 5, between 2000
and 2500")
for i in range(2000,2500):
if(i%17==0)and (not(i%5==0)):
print(i)

Practical 5
Swap two integer number using a temporary variable.
Repeat the exercise using the code format: a, b=b, a. Verify
your results in both the cases.
a=input('enter a no')
b=input('enter 2nd no')
c=a
a=b
b=c
print('Swaped value of a is',a)
print('Swaped value of b is',b)
print('Verifying the result')
a=int(input('enter a no'))
b=int(input('enter 2nd no'))
a,b=b,a
print('Swaped value of a is',a)
print('Swaped value of b is',b)
Practical 6:
Find the largest of n numbers, using a user defined function
largest().
def largest(arr,n):
max = arr[0]
for i in range(1,n):
if(arr[i]>max):
max = arr[i]
return max
arr=[10,2,15,3,54,15,615,1]
n=len(arr)
ans = largest(arr,n)
print("given array is :",arr)
print("largest in given array is",ans)

Practical 7:
Write a function myReverse() Which receives a string as an
input and returns the reverse of the string. Check if a given
string is palindrome or not.
def myReverse(s):
return s[::-1]
def isPalindrome(s):
rev=myReverse(s)
if(s==rev):
return True
return False
s=input("enter name ")
ans=isPalindrome(s)
if(ans==1):
print("yes name {} is Palindrome name".format(s))
else:
print("no name {} is not Palindrome name".format(s))
print(myReverse(s))

Practical 8:

WAP to convert Celsius to Fahrenheit


celcius=int(input("enter the temperature in celcius"))
f=(celcius*1.8)+32
print("temperature in farenheitis:",f)

Practical 9:
Find the ASCII value of characters
c= input("enter a character:")
print("the ASCII value of "+c+" is",ord(c))

Practical 10:
WAP for simple calculator

def simple_interest(p,t,r):
print('The principal is', p)
print('The time period is', t)
print('The rate of interest is',r)

si = (p * t * r)/100

print('The Simple Interest is', si)


return si

simple_interest(8, 6, 8)

You might also like