Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
242 views6 pages

Don Tamil Guide

12th tamil

Uploaded by

sivaarun200721
Copyright
© © All Rights Reserved
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
0% found this document useful (0 votes)
242 views6 pages

Don Tamil Guide

12th tamil

Uploaded by

sivaarun200721
Copyright
© © All Rights Reserved
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
You are on page 1/ 6

EX1A:

CALCULATE FACTORIAL

Write a program to calculate the factorial of the given number using for loop

AIM:
To write a program to calculate the factorial of the given number using for loop

PROGRAM CODING :

n = int(input("Enter a number:"))
fact=1
for i in range(1,n+1):
fact=fact*i
print("Factorial of" , n," is ",fact)

OUTPUT:
Enter a number: 6
Factorial of 6 is 720

EX1B:
SUM OF SERIES

Write a program to sum the series:1/1 + 22 /2 + 33 /3 + ……. nn/n

AIM:
To write a program to sum the series:1/1 + 22 /2 + 33 /3 + ……. nn/n

PROGRAM CODING:

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


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

OUTPUT:
Enter a value of n: 4
The sum of the series is 76
CONCLUSION:
The above programs were executed successfully.
________________________________________________________________________________

EX2A:
ODD OR EVEN

Write a program using functions to check whether a number is even or odd

AIM:
To write a program using functions to check whether a number is even or odd.

PROGRAM CODING :
def oddeven(a):
if(a%2==0):
return “Even”
else:
return “Odd”
n = int (input("Enter a number: "))
print(“The given number is “,oddeven(n))
OUTPUT 1:
Enter a number: 5
The given number is Odd

OUTPUT 2:
Enter a number: 8
The given number is Even

EX2B:
REVERSE THE STRING

Write a program to create a mirror of the given string. For example, “wel” = “lew“.

AIM:
To write a program to create a reverse of the given string.

PROGRAM CODING:
def reverse(str1):
str2=' '
for i in str1:
str2 = i + str2
return str2
word=input("\n Enter a String: ")
print("\n The reverse of the given string is:" , reverse(word))

OUTPUT 1:
Enter a String: MADAM
The reverse of the given string is: MADAM

OUTPUT 2:
Enter a String: COMPUTER
The mirror image of the given string is: RETUPMOC

CONCLUSION:
The above programs were executed successfully.

EX3:
GENERATE VALUES AND REMOVE ODD NUMBERS

Write a program to generate values from 1 to 10 and then remove all the
odd numbers from the list
AIM:
To write a program to generate values from 1 to 10 and then remove all the odd numbers from
the list

PROGRAM CODING:

num=list(range(1,11))
print("Numbers from 1 to 10...\n ", num)
for i in num:
if(i%2==1):
num.remove(i)
print("The values after removing odd numbers...\n", num)

OUTPUT:

Numbers from 1 to 10...


[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
The values after removing odd numbers...
[2, 4, 6, 8, 10]
CONCLUSION:
The above program was executed successfully.

________________________________________________________________________________

EX4:
GENERATE PRIME NUMBERS AND SET OPERATIONS

Write a Program that generate a set of prime numbers and another set of odd
numbers. Display the result of union, intersection, difference and symmetric
difference operations

AIM :

To write a Program that generate a set of prime numbers and another set of odd numbers.
Display the result of union, intersection, difference and symmetric difference operations

PROGRAM CODING:

odd=set(range(1,10,2))
prime=set()
for i in range(2,10):
for j in range(2,i):
if i%j==0:
break
else:
prime.add(i)
print("Odd Numbers : ",odd)
print("Prime Numbers : ",prime)
print("Union : ",odd.union(prime))
print("Intersection : ",odd.intersection(prime))
print("Difference : ",odd.difference(prime))
print("Symmetric Difference : ",odd.symmetric_difference(prime))

OUTPUT:
Odd Numbers : {1, 3, 5, 7, 9}
Prime Numbers : {2, 3, 5, 7}
Union : {1, 2, 3, 5, 7, 9}
Intersection : {3, 5, 7}
Difference : {1, 9}
Symmetric Difference : {1, 2, 9}
CONCLUSION:
The above program was executed successfully.

_______________________________________________________________________________

EX.5
DISPLAY STRING ELEMENTS – USING CLASS

Write a program to accept a string and print the number of uppercase, lowercase,
vowels, consonants and spaces in the given string using Class

AIM:

To write a program to accept a string and print the number of uppercase, lowercase, vowels,
consonants and spaces in the given string using Class.

PROGRAM CODING:
class String:
def __init__(self):
self.upper=0
self.lower=0
self.vowel=0
self.consonant=0
self.space=0
self.string=""
def getstr(self):
self.string=str(input("Enter a String"))
def count(self):
for ch in self.string:
if(ch.isupper()):
self.upper+=1
if(ch.islower()):
self.lower+=1
if(ch in('AEIOUaeiou')):
self.vowel+=1
if(ch == ‘ ‘):
self.space+=1
self.consonant=self.upper+self.lower-self.vowel
def display(self):
print("The String contains......")
print("%d Uppercase letters "%self.upper)
print("%d Lowercase letters "%self.lower)
print("%d Vowels "%self.vowel)
print("%d Consonants "%self.consonant)
print("%d Spaces"%self.space)
S=String()
S.getstr()
S.count()
S.display()

OUTPUT:

Enter a String: Welcome to Computer Science


The given string contains...
3 Uppercase letters
21 Lowercase letters
10 Vowels
17Consonants
3 Spaces

CONCLUSION:
The above program was executed successfully.

You might also like