KEMBAR78
XI CS PracticalFile | PDF | Numbers | Computer Programming
0% found this document useful (0 votes)
10 views35 pages

XI CS PracticalFile

Uploaded by

bhaisaad101abd
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)
10 views35 pages

XI CS PracticalFile

Uploaded by

bhaisaad101abd
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
You are on page 1/ 35

TABLE OF CONTENT

S. No. Practical Program List Page No


1 Write a program to print Factorial of a Number. 5

2 Write a program to print Compound Interest. 6

3 Write a program to print the Fibonacci series. 7

4 Write a program to check whether a Number is a Palindrome. 8

5 Write a program to find Sum of Digits of a Number. 9

6 Write a program to read an integer and print its multiplication table. 10

7 Write a program to print Sum of first N natural numbers. 11


Write a program to find the given Numbers is Armstrong Number or
8 not. 12
( 1,153,370,371,407)
Write a program to generate the sequence:
9 13
-5,10, -15,20, -25 ------up to n terms.

10 Write a program to check entered number is whether prime or not. 14

11 Write a program to print occurrence of a particular digit in a number. 15

12 Write a program to convert number from decimal to binary. 16

Write a program to find sum of the square of all natural numbers


13 from 1 to N. 17
Series: 1^2 + 2^2 + 3^2 + 4^2 +..N^2

Write a program to find the sum of Natural Number/Factorial of


14 Number of all natural numbers from 1 to N. 18
Series: 1/1! + 2/2! + 3/3! + 4/4! + ... N/N!

1
Write a program to input the value of x and n and print the sum of
15 the following series. 19
1+x+x2+x3+x4+. .......... xn

Write a program to count and display the number of vowels,


16 20
consonants, uppercase, lowercase characters in the string.

Write a program to input the value of x and n and print the sum of
17 the following series 21
e^x=1+x/1!+x^2/2!+x^3/3!+⋯n,-∞<x<∞

Write a program to find (calculate) the sum of series


18 22
1+11+111+1111+... till N terms

Write a program to print following Pyramid


ABCDEEDCBA
ABCD DCBA
19 24
ABC CBA
AB BA
A A

Write a program to print following Pyramid:


1 1
12 21
20 26
123 321
1234 4321
1234554321

2
Write a program to print following Pyramid:
1
123
21
12345
1234567
123456789

28

Write a program to print following Pyramid:


**********
**** ****
22
*** ***
** **
* *

29

Write a program to print following Pyramid:

*
**
***
****
23
*****
*****
****
***
**
*

31

3
Write a program to print character pyramid as given below:
A
BC
24 34
DEF
GHIJ
KLMNO

Write a program to print following Pyramid:

*****
****
25 *** 35
**
*

4
1. Write a program to print Factorial of a Number.

fact = 1
number = int(input("Enter Number: "))
i=1
while i<= number:
fact = fact * i
i= i + 1
print("Factorial of %d is %d "%(number, fact))

Input / Output

5
2. Write a program to print Compound Interest.

# Python program to find compound interest


p = float(input("Enter the principle amount : "))
r = float(input("Enter the rate of interest : "))
t = float(input("Enter the time in the years: "))

# calculating compound interest


ci = p * (pow((1 + r / 100), t))

# printing the values


print("Principle amount : ", p)
print("Interest rate : ", r)
print("Time in years : ", t)
print("compound Interest : ", ci)

Input / Output

6
3. Write a program to print the Fibonacci series.

#program to print the Fibonacci series.


first = 0
second = 1
third = 0
n= int(input("Enter Number of term to print : "))
i=3
if n == 1 and n>0:
print(first)
elif n == 2 :
print(first," " ,second,end="")
else:
print(first," " ,second,end="")
while i <= n :
third = first + second
print(" ",third,end="")
first = second
second = third
i=i+1
print("\nEnd of Program")

Input / Output

7
4. Write a program to check whether a Number is a Palindrome.
#Program to check whether a Number is a Palindrome.
rev_number = 0
remainder = 0
number = int(input("Enter Number: "))
temp = number
#the number is reversed inside the while loop.
while temp > 0:
remainder = temp % 10;
rev_number = (rev_number * 10) + remainder;
temp = temp//10
#print("rev ",rev_number)
if number == rev_number:
print("A Number is a Palindrome")
else:
print("A Number is not a Palindrome")

Input / Output

8
5. Write a program to find Sum of Digits of a Number.

#Program to find Sum of Digits of a Number.

remainder = 0
number = int(input("Enter Number: "))
total = 0
while number != 0:
remainder = number % 10;
total = total+ remainder;
number = number//10
print("Sum of the digits of the entered number is = ",total)

Input / Output

9
6. Write a program to read an integer and print its multiplication
table.

#Write a program to read an integer and print its multiplication table.


number = 0#to store number
i = 1#Initialising loop counter
number = int(input("Enter Number: "))
while i<= 10:#loop from 1 to 10
print(" ",number * i)
i= i + 1 #Increase loop counter
#End of the loop

Input / Output

10
7. Write a program to print Sum of first N natural numbers.

#Program to print Sum of first N natural numbers.


number = 0#to store number
sum = 0
number = int(input("Enter Number: "))
i = 1 #Initialising loop counter

while i<=number:#loop from 1 to number


sum = sum + i
i=i+1
print("Sum is : ",sum)

Input / Output

11
8. Write a program to find the given Numbers is Armstrong
Number or not.
(Example of Armstrong Number :- 1,153,370,371,407)

#Program to find the given Numbers is Armstrong Number or not.


number = 0#to store number
rem = 0
sum = 0
number = int(input("Enter Number: "))
temp = number #Initialising loop counter

while temp!=0:#loop from 1 to number


rem = temp % 10
sum = sum + (rem * rem * rem)
temp = temp//10
if sum == number:
print("The given Numbers is Armstrong Number",number)
else:
print("The given Numbers is not Armstrong Number",number)

Input / Output

12
9. Write a program to generate the sequence:
-5,10, -15,20, -25 ------up to n terms.

#Program to generate the sequence: -5,10, -15,20, -25 ------up to n terms.


limit = int(input("Enter Limit : "))
sign = -1
term = 0
number = 5
i=1
while i<=limit:
term = number * sign
sign = sign * -1
print(term,end=" ")
number = number + 5
i=i+1
#End of loop
#End of Program

Input / Output

13
10. Write a program to check entered number is whether
prime or not.

#Program to check entered number is whether prime or not.


number = 0
i=2
flag = True
number = int(input("Enter an integer number : "))#input number
while i<= (number//2): #start Loop
if (number % i) == 0:
flag = True
break
#Condition Ended
i=i+1
#End of While Loop
if flag == True:
print("%d is a prime number" %number)
else:
print("%d is not a prime number" %number)
Input / Output

14
11. Write a program to print occurrence of a particular digit in
a number.
#Program to print occurrence of a particular digit in a number.
rem = 0
count = 0
num = int(input("Enter a number:"))
digit = int(input("Enter digit to search:"))
temp = num
while num > 0:
rem = num % 10;
if(rem ==digit):
count = count + 1
#end of codition
num = num // 10;
#end of while
print("Total occurrence of digit is: ",count," in number: ",temp)

Input / Output

15
12. Write a program to convert number from decimal to
binary.
#Program to convert number from decimal to binary.
number = 0
bin = 0
count = 0
number = int(input("Enter decimal number : "))
print("Binary value is: ",end = " ")
while number > 0 :
bin = number % 2;
print(bin,end = "")
number = number//2;
count = count+1;

Input / Output

16
13. Write a program to find sum of the square of all natural
numbers from 1 to N.
Series: 1^2 + 2^2 + 3^2 + 4^2 +..N^2
#program to find sum of the square of all natural numbers from 1 to N.
#Series: 1^2+2^2+3^2+4^2+..N^2
num = 2
total = 0
i=1
#calculate sum of the series
while i<=num :
total = total + ( i * i)
i=i+1
#print the sum
print("Sum of the series is: ",total)

Input / Output

17
14. Write a program to find the sum of Natural Number/
Factorial of Number of all natural numbers from 1 to N.
Series: 1/1! + 2/2! + 3/3! + 4/4! + ... N/N!
program to find the sum of Natural Number/Factorial of Number of all natural
numbers from 1 to N.
#Series: 1/1! + 2/2! + 3/3! + 4/4! + ... N/N!
num = 10
fact = 1
total = 0
i=1
#calculate sum of the series
while i<=num :
fact = fact * i
total = total + (i / fact)
i=i+1

#print the sum


print("Sum of the series is: ",total);

Input / Output

18
15. Write a program to input the value of x and n and print the
sum of the following series.
1+x+x2+x3+x4+. .......... xn
# take input from user and typecast into integer
i=1
sum = 1
power = 1
x = int(input("Enter a number( base ): "))
n = int(input("Enter a number of terms: "))
# iterating till n//2 value
while(i < n ) :
power = power * x
print(power)
sum = sum + power
i=i+1
print("Sum of series :",sum)

Input / Output

19
16. Write a program to count and display the number of
vowels, consonants, uppercase, lowercase characters in the
string.

string = input("Enter Your String : ")


vowels = consonants = uppercase = lowercase = 0
vowels_list = ['a','e','i','o','u']
for i in string:
if i in vowels_list:
vowels += 1
if i not in vowels_list:
consonants += 1
if i.isupper():
uppercase += 1
if i.islower():
lowercase += 1
print("Number of Vowels in this String = ", vowels)
print("Number of Consonants in this String = ", consonants)
print("Number of Uppercase characters in this String = ", uppercase)
print("Number of Lowercase characters in this String = ", lowercase)

Input / Output

20
17. Write a program to input the value of x and n and print the
sum of the following series.
e^x=1+x/1!+x^2/2!+x^3/3!+⋯n,-∞<x<∞

x = int(input("Enter the value of x: "))


term = int(input("Enter Term : "))
sum = 0
m=1

for i in range(1, term) :


fact = 1
for j in range(1, i+1) :
fact *= j
term = x ** i / fact
sum += term * m
m = m * -1

print("Sum =", sum)

Input / Output

21
18. Write a program to find (calculate) the sum of series
1+11+111+1111+... till N terms.

#Program to find (calculate) the sum of series 1+11+111+1111+... till N terms

terms=0 #to store total terms

i=0 #to run loop;

sum=0 #to store sum of values % assign 0 to sum

temp = 1 #to add the diff or initial term value, 1 as initial term value

terms=int(input("Enter total number of terms: ")) #input total terms

#run loop to find sum of each value and then increase it with the differences

while(i<terms):

#print the value

print(temp,end=' ');

#print '+' sign in the series

if i < terms-1:

print("+ ",end='')

#add the value and store in sum

sum += temp;

#update/increase the value

temp = (temp * 10) + 1

i +=1

#print the value of sum of the series

print("\nSUM of the series is: ",sum)

22
Input / Output

23
19. Write a program to print following Pyramid
ABCDEEDCBA
ABCD DCBA
ABC CBA
AB BA
A A
#For upper Pyramid
ch ='A'
i=5
j=0
space = 0
while i>0 :
#outer loop start
#print first set of stars
ch ='A'
j=0
while j<i :
#inner loop start
print(ch,end='')
ch =chr(ord(ch) + 1)
j=j+1
#inner loop End
j=0
while j<space :
#inner loop start
print(" ",end='')
j=j+1
#inner loop End
j=0
ch =chr(ord(ch) - 1)
while j<i :
#inner loop start
print(ch,end='')
ch =chr(ord(ch) - 1)
j=j+1
24
#inner loop End
print("")
space = space + 1
i=i-1
#outer loop End

Input / Output

25
20. Write a program to print following Pyramid.
1 1
12 21
123 321
1234 4321
1234554321

#For upper Pyramid


i=1
j=0
k=0
l=0
m=8
n=1
while i<=5 :
#outer loop start
j=1
while j<=i :
#inner loop start
print(j,end='')
j=j+1
#inner loop End
k=m
while k>=l :
#inner loop start
print(" ",end='')
k=k-1
#inner loop End
m=m-2
l=n
while l>=1 :
#inner loop start
print(l,end='')
#inner loop End
l= l - 1
26
n=n+1
print("")
i=i+1
#outer loop End

Input / Output

27
21. Write a program to print following Pyramid.
1
123
12345
1234567
123456789

#For upper Pyramid


i=0
j=0
l=0
while i<=5 :
#outer loop start
j=4
while j>=i :
#inner loop start
print(" ",end='')
j=j-1
#inner loop End
j=1
while j<l :
#inner loop start
print(j,end='')
j=j+1 Input / Output
#inner loop End
l= l +2
print("")
i=i+1
#outer loop End

28
22. Write a program to print following Pyramid:
**********
**** ****
*** ***
** **
* *

#For upper Pyramid


i=5
j=0
space = 0
while i>0 :
#outer loop start
#print first set of stars
j=0
while j<i :
#inner loop start
print("*",end='')
j=j+1
#inner loop End
j=0
while j<space :
#inner loop start
print(" ",end='')
j=j+1
#inner loop End
j=0
while j<i :
#inner loop start
print("*",end='')
j=j+1
#inner loop End
print("")
space = space + 1
29
i=i-1
#outer loop End

Input / Output

30
23. Write a program to print following Pyramid:

*
**
***
****
*****
*****
****
***
**
*

#For upper Pyramid

i=0

j=0

space = 4

while i<=5 :

#outer loop start

j=0

while j<=space :

#inner loop start

print(" ",end='')

j=j+1

#inner loop End

j=0

while j<=i :

31
#inner loop start

print("*",end=' ')

j=j+1

#inner loop End

print("")

space = space - 1

i=i+1

#outer loop End

#For Down Pyramid

i=5

j=0

space = 0

while i>0 :

#outer loop start

j=0

while j<=space :

#inner loop start

print(" ",end='')

j=j+1

#inner loop End

j=0

while j<i :

#inner loop start


32
print("*",end=' ')

j=j+1

#inner loop End

print("")

space = space + 1

i=i–1

Input / Output

33
24. Write a program to print character pyramid as given
below:
A
BC
DEF
GHIJ
KLMNO
ch = None
i=1
j=1
ch ='A'
while i<=5 :
#outer loop start
j=1
while j<=i :
#inner loop start
print(ch,end=' ')
ch =chr(ord(ch) + 1)
j=j+1
#inner loop End
print("")
i=i+1
#outer loop End Input / Output

34
25. Write a program to print following Pyramid:
*****
****
***
**
*
ch = None
i=5
j=1
ch ='A'
while i>=0 :
#outer loop start
j=1
while j<=i :
#inner loop start
print("*",end='')
j=j+1
#inner loop End
print("")
i=i-1
#outer loop End

Input / Output

35

You might also like