60% found this document useful (5 votes)
931 views2 pages

Class 12 Python Practical Programs

This document contains 5 code snippets that demonstrate various Python programming concepts: 1. Calculates the factorial of a user-input number. 2. Checks if a user-input number is even or odd, and reverses a user-input string. 3. Removes odd numbers from a list of numbers from 1 to 10. 4. Performs set operations on odd numbers and prime numbers. 5. Counts the number of uppercase letters, lowercase letters, vowels, consonants, and spaces in a user-input string.

Uploaded by

rsgk
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
60% found this document useful (5 votes)
931 views2 pages

Class 12 Python Practical Programs

This document contains 5 code snippets that demonstrate various Python programming concepts: 1. Calculates the factorial of a user-input number. 2. Checks if a user-input number is even or odd, and reverses a user-input string. 3. Removes odd numbers from a list of numbers from 1 to 10. 4. Performs set operations on odd numbers and prime numbers. 5. Counts the number of uppercase letters, lowercase letters, vowels, consonants, and spaces in a user-input string.

Uploaded by

rsgk
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1 num=int(input("Enter a Number:")) n=int(input("Enter a value of n:"))

if(num==0): s=0
fact=1 for i in range(1,n+1):
else: a=float(i**i)/i
fact=1 s=s+a
for i in range(1,num+1): print("The sum of the series is",s)
fact=fact*i

print("Factorial of",num,"is",fact)
2 def oddeven(a): def rev(str1):
if (a%2==0): str2=''
return 1 i=len(str1)-1
else: while i>=0:
return 0 str2+=str1[i]
i-=1
num=int(input("enter a number:")) return str2
word=input("\n Enter a String:")
if(oddeven(num)==1): print("\n The Mirror image of the given string is:",rev(word))
print("The given number is Even")
elif(oddeven(num)==0):
print("The given number is Odd")
3 num1=[]
for i in range(1,11):
[Link](i)

print("Numbers from 1 to 10...\n",num1)


for j,i in enumerate(num1):
if(i%2==1):
del num1[j]

print("The values after removed odd numbers...\n",num1)


4 odd=set([x*2+1 for x in range(0,5)])

primes=set()
for i in range(2,10):
j=2
f=0
while j<=i/2:
if i%j==0:
f=1
j+=1
if f==0:
[Link](i)

print("Odd Numbers:",odd)
print("Prime Number:",primes)
print("Union:",[Link](primes))
print("Intersection:",[Link](primes))
print("Difference:",[Link](primes))
print("Symmetric Difference:",odd.symmetric_difference(primes))
5 class string:

def __init__(self):
[Link]=0
[Link]=0
[Link]=0
[Link]=0
[Link]=0
[Link]=""

def getstr(self):
[Link]=str(input("enter a String:"))

for ch in [Link]:
if([Link]()):
[Link]+=1

if([Link]()):
[Link]+=1

if(ch in('a','A','e','E','i','I','o','O','u','U')):
[Link]+=1

if(ch not in('a','A','e','E','i','I','o','O','u','U',' ')):


[Link]+=1

if(ch==" "):
[Link]+=1

def display(self):
print("the given string contains....")
print("%d Uppercase letters"%[Link])
print("%d Lowercase letters"%[Link])
print("%d Vowels"%[Link])
print("%d Consonants"%[Link])
print("%d Spaces"%[Link])

s=string()
[Link]()
[Link]()

You might also like