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

Python Practicals

The document contains several Python scripts for practical exercises, including counting vowels, digits, special characters, and consonants in a string, removing a word or letter from a string, sorting a list, calculating the sum of list elements, and determining a student's grade based on marks. It also includes a script to check if a number is an Armstrong number. Each script is presented with input prompts and expected outputs.

Uploaded by

jemisunagar28
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 views3 pages

Python Practicals

The document contains several Python scripts for practical exercises, including counting vowels, digits, special characters, and consonants in a string, removing a word or letter from a string, sorting a list, calculating the sum of list elements, and determining a student's grade based on marks. It also includes a script to check if a number is an Armstrong number. Each script is presented with input prompts and expected outputs.

Uploaded by

jemisunagar28
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/ 3

Python Practicals:

__________________________________________________________________________________

# CHARACTER & STRING:


# Write a python script that count number of vowels, digit, special
character, spaces and consonants from the string.

s=input("Enter a String : ")


v=d=sp=sc=c=0
for i in s:
if i in "aeiouAEIOU":
v=v+1
elif i in " ":
sp=sp+1
elif i in "0123456789":
d=d+1
elif i in "!@#$%^&*()_-+=[]{}|;:.,></?":
sc=sc+1
else:
c=c+1
print("Number of Vowels : ",v)
print("Number of Digit : ",d)
print("Number of special character : ",sc)
print("Number of Space : ",sp)
print("Number of Consonants : ",c)

__________________________________________________________________________________

#Write a python script that remove given word from the string.
'''
s=input("Enter a String : ")
w=input("Enter a word to remove : ")
l=s.split()
if w in l:
l.remove(w)
ns=" ".join(l)
print("String after removing given word is :\n",ns)
'''
__________________________________________________________________________________

#WritE a python script that remove a latter from the given position.
'''
s=input("Enter a String : ")
p=int(input("Enter position to remove latter : "))
l=list(s)
l.pop(p)
ns="".join(l)
print("After removing latter : ",ns)
'''
_________________________________________________________________

#NUMBER:

__________________________________________________________________________________

#Create a python script that perform the following task.


#a. Sort the list
#b. Display sum of the elements of the list
#c. Display last element of the list

n=int(input("Enter Number of element in list : "))


lst1=[]
for i in range(n):
x=int(input("Enter an element : "))
lst1.append(x)

print("Your List is : ",lst1)


lst1.sort()
print("List after sorting (Asc) : ",lst1)
lst1.sort(reverse=True)
print("List after sorting (Desc) : ",lst1)

#SUM OF ALL ELEMENTS OF LIST


s=0
for i in lst1:
s=s+i
print("Sum of all element is : ",s)
print("Last element is : ",lst1[-1]) #PRINTING LAST ELEMENT OF LIST

_________________________________________________________________________________

#Write a python script that take input of 3 subject’s marks. Find


Percentage and Grade of the student.

print("Enter Marks details...")


ps=int(input("Enter Marks for PS : "))
os=int(input("Enter Marks for OS : "))
rd=int(input("Enter Marks for RD : "))
total=ps+os+rd
print("Total marks is : ",total)
per=(total*100)/300
print("Per of marks is : ",per)
if(per > 70):
print("Have DIST class")
elif(per > 60):
print("Have A class")
elif(per > 50):
print("Have B class")
elif(per > 40):
print("Have Pass class")
else:
print("Failed in exam")
__________________________________________________________________________________

#Create a python script to find whether a number is Armstrong number or


not.

n=input("Enter a number :")


r=len(n)
s=0
for i in n:
s=s+pow(int(i),r)
n=int(n)
if n==s:
print("Number is an Armstrong number")
else:
print("Number is not an Armstrong number")

You might also like