Xii Python Computer Science Practicals English Medium
Xii Python Computer Science Practicals English Medium
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):
num1.append(i)
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:
primes.add(i)
print("Odd Numbers:",odd)
print("Prime Number:",primes)
print("Union:",odd.union(primes))
print("Intersection:",odd.intersection(primes))
print("Difference:",odd.difference(primes))
print("Symmetric Difference:",odd.symmetric_difference(primes))
5 class string:
def __init__(self):
self.uppercase=0
self.lowercase=0
self.vowels=0
self.consonants=0
self.spaces=0
self.string=""
def getstr(self):
self.string=str(input("enter a String:"))
for ch in self.string:
if(ch.isupper()):
self.uppercase+=1
if(ch.islower()):
self.lowercase+=1
if(ch in('a','A','e','E','i','I','o','O','u','U')):
self.vowels+=1
if(ch==" "):
self.spaces+=1
def display(self):
print("the given string contains....")
print("%d Uppercase letters"%self.uppercase)
print("%d Lowercase letters"%self.lowercase)
print("%d Vowels"%self.vowels)
print("%d Consonants"%self.consonants)
print("%d Spaces"%self.spaces)
s=string()
s.getstr()
s.display()