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

English

English pdf

Uploaded by

mohanandi383
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)
4 views6 pages

English

English pdf

Uploaded by

mohanandi383
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

1(a) - Calculate Factorial Enter a Number: 0

AIM The Factorial of 0 is 1

Program to calculate the factorial of Enter a Number: 5


the given number using for loop
The Factorial of 5 is 120
Coding

num = int(input("Enter a Number: "))


1(b) - Sum of Series
fact = 1
AIM
if (num<0):
Program to sum the given series.
print("Factorial does not exist…" )
Coding
elif [num==0]:
n = int(input("Enter the range of
print("The Factorial of”num exist." )
term: "))
else:
s=0.0
for i in range(1,num1+):
for i in range(1,n+1):
fact = fact * i
a=float(i**i)/i
print("The Factorial of ", num, " is ",
s=s+a
fact)
print("The sum of the series is ", s)
Result:
Result:
The factorial of the given number is
calculated successfully using for The sum of the given series is
loop. calculated successfully.

Output: Output:

Enter a Number: -6 Enter a value of n: 4

Factorial does not exit The sum of the series is 76.0


2(a) - Odd or Even 2(b) - Reverse the String

AIM AIM

Program using functions to check Program to create a mirror of the


whether a number is even or odd given string.
using function
Coding
Coding
Text = input (“Enter a text”)
Def odd even(num):
m text ='' “
if (num%2==1):
for ch in text:
print("The given number is Odd")
m tech = ch+ m text
else:
print("The Enter a String: "text)
print("The given number is Even")
print(" The Mirror image of the given
return string is: ", m text)

n = int(input("Enter a number: "))

oddeven (n). Result:

Result: The mirror image of the given string


is displayed successfully.
It was successfully verified
whether the given number is even or
odd.
Output:
Output:
Enter a String: school
Enter a number: 5
The entered string is: School
The given number is Odd
The Mirror image of the given string:
Enter a number: 8 loohcs

The given number is Even


3 – Generate values and remove odd
numbers
Output:
AIM
The Numbers in the list.....
Program to generate values from 1
[1,2,3,4,5,6,7,8,9,10]
to 10 and then remove all the odd
numbers from the list The values after removed odd
numbers.....
Coding
[2,4,6,8,10]
1st=[]

for i in range(1,11):

[Link](i)

Print("The Numbers in the list…”)

Print(1st)

for i in 1st:

if i %2==1:

1st remove[i]

print("The values after removed odd


numbers..”)

Print(1st)

RESULT

All odd numbers were successfully


froms the list
4 – Generate Prime numbers and Set print("Difference: ",
Operations [Link](primes))

AIM print("Symmetric Difference: ",


odd.symmetric_difference(primes))
Program that generate a set of
prime numbers and another set

of odd numbers and then perform Result


various set operations
Prime number and odd number set
are generated and then performed
various set operations successfully.
Coding

odd=set(i for i in range(1,10,2))

prime=set()
Output:
for num in range(1,11):
Odd Numbers: {1 ,3 ,5 ,7 ,9}
if num>1:
Prime Numbers: {2 ,3 ,5 ,7}
for i in range [2,num]:
Union: {1,2,3,4,5,6,7,8,9}
if [num% i ]==0:
Intersection: {3,5,7}
break
Difference: {1,9}
else:
Symmetric Difference: {1,2,9}
[Link](num)

print("Odd Numbers: ", odd)

print("Prime Numbers: ", primes)

print("Union: ", [Link](primes))

print("Intersection: ",
[Link](primes))
5 – Display sting elements – Using if (ch in ('aeiou AEIOU')):
Class
self.v+=1
AIM
if (ch==""):
Program to accept a string and print
self.b+=1
the number of uppercase, vowels,
constant and spaces in the given self.c= self.u+ self.l- self.v
string using Class
def display(self):
Coding
Print("The given string is:" [Link])
class String:
Print("Uppercase letters"self.u)
def __init__(self):
Print("Lowercase letters"self.l)
self. u=0
Print(" Vowels letters"self.v)
self.l=0
Print(" Constants letters"self.c)
self.v=0
Print("Bank Spaces"self.b)
self.c=0
S = String()
self.b =0
[Link]()
[Link]=""
[Link]()
def get str(self):

[Link]=input("Enter a String: ")

for ch in [Link]:
RESULT:
if ([Link]()):
The number of
self.u+=1 uppercase ,lowercase, vowels,
constant and spaces are counted
if ([Link]()):
successfully in the given string users.
self.l+=1
Output:

Enter a String: Welcome to


Computer Science

The given string is: Welcome to


Computer Science

Uppercase letters:3

Lowercase letters:21

Vowels letters:10

Constnants letters:14

Blank Space:3

You might also like