Cs Practical File Class 11

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

No.

Practical Date Signature


1 Write a python program to input a welcome message and display it.
2 Write a python program to input two numbers and display the larger / smaller
number.
3 Write a python program to input three numbers and display the largest /
smallest number.
4 Generate the following patterns using nested loop.

5 Write a program to input the value of x and n and print the sum of the following
series:
a. 1 + x² + x³ + ... + xⁿ
b. x - x2/2! + x3/3! - x4/4! + x5/5! - x6/6!
6 Write a program to determine whether a number is a perfect number, an
Armstrong number or a palindrome.
7 Write a program to input a number and check if the number is a prime or
composite number.
8 Write a program to display the n terms of a Fibonacci series.
9 Write a python program to compute the greatest common divisor and least
common multiple of two integers.
10 Write a program to count and display the number of vowels, consonants,
uppercase, lowercase characters in string.
1. Write a python program to input a welcome message and display it.
wl_msg = input(“Enter the welcome message:”)
print(wl_msg)

2. Write a python program to input two numbers and display the larger / smaller number.
n1=int(input(“Enter number1 n1=input("Enter the first
number to check:")
n2=input("Enter the second number to check:")

#Checking Larger
if n1>n2:
print(n1," is larger.")
elif n2>n1:
print(n2," is larger")
else:
print("You have entered equal number.")

#Checking Smaller
if n1<n2:
print(n1," is smaller.")
elif n2<n1:
print(n2," is smaller")
else:
print("You have entered equal number.")
3. Write a python program to input three numbers and display the largest / smallest number.
n1=input("Enter the first number to check:")
n2=input("Enter the second number to check:")
n3=input("Enter the third number to check:")

#Checking Largest
if n1>n2 and
n1>n3:
print(n1," is largest.")
elif n2>n1 and n2>n3:
print(n2," is largest")
elif n3>n1 and n3>n2:
print(n3," is largest")
else:
print("You have entered equal number.")

#Checking Smallest
if n1<n2 and n1<n3:
print(n1," is smallest.")
elif n2<n1 and n2<n3:
print(n2," is smallest")
elif n3<n1 and n3<n2:
print(n3," is smallest")
else:
print("You have entered equal number.")
4. Generate the following patterns using nested loop.

#Code For Pattern1

for i in range(1,6):

for j in range(1,i+1):

print("*",end=" ")

print()

#Code for Pattern2

for i in range(6,1,-1):

for j in range(1,i):

print(j,end=" ")

print()

#code for pattern 3

for i in range (65,70):

for j in range(65,i+1):

print(chr(j),end="")

print()
5. Write a program to input the value of x and n and print the sum of the following series:
a. 1 + x² + x³ + ... + xⁿ
b. x - x2/2! + x3/3! - x4/4! + x5/5! - x6/6!

x = float (input ("Enter value of x :"))


n = int (input ("Enter value of n :"))
s = 0
#Series 1
for i in range (n+1) :
s += x**i
if i<n:
print(x**i,"+",end=" ")
else:
print(x**i,end=" ")
print ("=", s)

#Series 2
sum = 0
m = 1
for i in range(1, 7) :
f = 1
for j in range(1, i+1) :
f *= j
t = x ** i / f
if i==1:
print(int(t),end=" ")
elif i%2==0:
print("-",int(t),end=" ")
else:
print("+",int(t),end=" ")
sum += t * m
m = m * -1
print(" =", sum)
Series 1:

Series 2:
6. Write a program to determine whether a number is a perfect number, an Armstrong number or a
palindrome.
n=int(input("Enter a number to check:"))
temp = n
cnt=0
rev=0

#Check for a perfect number


for i in range(1,n):
if n%i==0:
cnt+=i
if cnt==n:
print(n," is perfect number")
else:
print(n," is not a perfect number")

#Check for an armstrong number

while temp > 0:


digit = temp % 10
cnt += digit ** 3
temp //= 10 # Armstrong number is a number that is
equal to the sum of cubes of its digits
if n == cnt:
print(n, "is an Armstrong number")
else:
print(n, "is not an Armstrong number")

#Check for palindrome

while n > 0: #if n is greater than 0 this loop runs


dig = n % 10
rev = rev * 10 + dig #This loop calculates the
reverse and matches it with input
n = n // 10
if temp == rev:
print(temp, "The number is a palindrome!")
else:
print(temp, "The number isn’t a palindrome!")
Output:

7. Write a program to input a number and check if the number is a prime or composite number.
n=int(input("Enter number to check:"))
if n>1:
for i in range(2,n):
if n%i==0:
f=1
break
else:
f=0
elif n==0 or n==1:
print(n, " is not a prime number nor composite
number")
else:
print(n," is a composite number")

if f==1:
print(n, " is not a prime number")
else:
print(n," is a prime number")
8. Write a program to display the n term Fibonacci series.
nterms = int(input("Enter number of terms to display:
"))

# first two terms


n1, n2 = 0, 1
count = 0

# check if the number of terms is valid


if nterms <= 0:
print("Please enter a positive integer")
# if there is only one term, return n1
elif nterms == 1:
print("Fibonacci sequence upto",nterms,":")
print(n1, end=” ”)
# generate fibonacci sequence
else:
print("Fibonacci sequence:")
while count < nterms:
print(n1)
nth = n1 +
n2
# update values
n1 = n2
n2 = nth
count += 1

9. Write a python program to compute the greatest common divisor and least common multiple of two
integers.
# Reading two numbers from user
fn = int(input('Enter first number: '))
sn = int(input('Enter second number: '))
gcd = 1
for i in range(1,fn +1):
if fn%i==0 and sn%i==0:
gcd = i
# Displaying GCD
print('HCF or GCD of %d and %d is %d' %(fn, sn,gcd))
# Calculating LCM
lcm = fn * sn/ gcd
print('LCM of %d and %d is %d' %(fn, sn, lcm))
10. Write a program to count and display the number of vowels, consonants, uppercase, lowercase
characters in string.
txt = input("Enter Your String : ")

v = c = uc = lc = 0

v_list = ['a','e','i','o','u']

for i in txt:

if i in v_list:

v += 1

if i not in v_list:

c += 1

if i.isupper():

uc += 1

if i.islower():

lc += 1

print("Number of Vowels in this text = ", v)

print("Number of Consonants in this text = ", c)

print("Number of Uppercase letters in this text=", uc)

print("Number of Lowercase letters in this text=", lc)

You might also like