0% found this document useful (0 votes)
268 views

CS Project Class 11th Python Programs

The document is a practical file submitted by Sudhanshu of class XI-C for the subject of Computer Science. It contains a certificate signed by the teacher certifying that the practical file contains the individual work of Sudhanshu. The file also contains an index listing 21 programs written by Sudhanshu along with their codes, inputs, and outputs. The programs include finding multiplication tables, determining the greater of two numbers, checking for Armstrong, perfect, and palindrome numbers, finding the greatest of three numbers, determining prime and composite numbers, and calculating numerical series.

Uploaded by

saksham
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
268 views

CS Project Class 11th Python Programs

The document is a practical file submitted by Sudhanshu of class XI-C for the subject of Computer Science. It contains a certificate signed by the teacher certifying that the practical file contains the individual work of Sudhanshu. The file also contains an index listing 21 programs written by Sudhanshu along with their codes, inputs, and outputs. The programs include finding multiplication tables, determining the greater of two numbers, checking for Armstrong, perfect, and palindrome numbers, finding the greatest of three numbers, determining prime and composite numbers, and calculating numerical series.

Uploaded by

saksham
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 27

New Delhi Public School

A-Block, Vikas Puri

Practical File
2021-22

Name : Sudhanshu
Class : XI – C
Subject : Computer Science
Submitted to : Saurabh Bhutani
Certif
This is to certify that
XI-C hasicate Sudhanshu of class
successfully
completed the project work on
Computer Science for class XI practical examination of the
Central Board of Secondary Education in the year 2021-22 . It is
further certified that this project is the individual work of the
candidate

Teacher Sign
Index
S No. Programs Dat Remarks
e
1. Write a program to display a Multiplication Table
of a number inputted by the user.
2. Write a program to input two numbers and
display the larger/smaller number
3. Write a program to determine whether a number
is an Armstrong number or not.
4. Write a program to determine whether a number
is a Perfect number or not
5. Write a program to determine whether a number
is a Palindrome Number or not
6. Write a program to input three numbers and
determine the greatest number
7. Write a program to determine whether a number
is prime or composite
8. Write a program to get the sum of this series 1 +
x + x**2 + x**3 + x**4 + ..... + x**n
9. Write a program to get the sum of this series 1 –
x + x**2 - x**3 + x**4 + ..... + x**n
10. Write a program to determine the sum of the
series x - x**2/2 + x**3/3 - x**4/4 + ........... +
x**n/n
11. Write a program to get the sum of the series x +
x**2/2! - x**3/3! + x**4/4! + ........... + x**n/n!
12. Write the program to print the Pattern 12345
1234
123
12
1

13. Write the program to print the Pattern *****


****
***
**
*
14. Write a program to determine the greatest
common divisor and least common multiple
15. Write a program to determine how many
vowels, consonants, uppercase, and lowercase
are present in the text
16. Display the terms of the Fibonacci series

17. Input a string and determine whether it is a


palindrome or not
18. Convert the case of characters in a string

19. Write a program to print the pattern A


AB
ABC
ABCD
ABCDE
20. Convert Celsius to Fahrenheit or visa versa.

21. Write a program which tells about how many


alphabets, digit, lowercase and uppercase
characters are present in a sentence
22. Write a program to remove all the vowels from
the sentence or string

Ques 1. Write a program to display a Multiplication Table of a number


inputted by the user.
Code :

number = int(input('Enter a Number : ')) # take a number as input


i=1
print('Table of ',number ,'from 1 to 10 ')
while i <= 10:
print(number, '*' ,i ,'=' ,i*number)
i+=1

Running Code :

Input as 150

Output

Ques 2. Write a program to input two numbers and display the


larger/smaller number.
Code :
number1 = int(input('Enter 1st Number : '))
number2 = int(input('Enter 2nd Number : '))

if number1 > number2 :


print('1st Number is greater than 2nd Number i.e. ',number1 ,
'>' ,number2)
else:
print('2nd Number is greater than 1st Number i.e. ',number2 ,
'>' ,number1)

Running Code :

Input as 10 and 20 or visa versa

Output

Ques 3. Write a program to determine whether a number is an Armstrong


number or not.
Code :

number = int(input('Enter a number : ')) # take a input


str1 = str(number) # convert integer to string
n = len(str1) # get the length of string
i=0
tsum = 0
while i < n : # loop to get the sum of cubes of all digit in numbers
cube = int(str1[i])**3
tsum+=cube
i+=1
if tsum == number : # compare the values
print('Yes! , ',number,' is a Armstrong Numbers')
else :
print('No! , ',number,' is not a Armstrong Numbers')

Running Code :

Input

Output
Ques 4. Write a program to determine whether a number is a Perfect
number or not.

Code :

number = int(input('Enter a Number : ')) # input a number from user


i = 0
tsum = 0
while i < number : # loop to get the sum of all perfect divisor
i+=1
if number % i == 0 :
if number != i :
tsum += i
if tsum == number : # check whether it is perfect number or not
print('Yes! ,', number,' is a Perfect Number')
else:
print('No! ,', number,' is not a Perfect Number' )

Running Code :

Input

Ouput
Ques 5. Write a program to determine whether a number is a Palindrome
Number or not.

Code :

number = int(input('Enter a number : ')) # input a number


str1 = str(number) # convert the integer to string
n = len(str1)
i = 0
while i <= n : # loop to get whether it is a Palindrome
if str1[i] != str1[n-i-1]:
print('No! ',number,' is not a Palindrome number')
break
elif i > n/2 :
print('Yes! ,',number,' is a Palindrome number')
break
else:
i+=1

Running Code :

Input

Output
Ques 6. Write a program to input three numbers and determine the
greatest number.
Code :

number1 = int(input('Enter 1st Number : '))# input three numbers


number2 = int(input('Enter 2nd Number : '))
number3 = int(input('Enter 3rd Number : '))
if number1 == number2 == number3 : # determining the greatest digit
print('all the numbers are same. please try again !')
elif number1 == number2 :
if number1 > number3 :
print(number1, 'and' ,number2, 'are greater than ',number3)
else :
print(number3, 'is greater than ',number1, 'and' ,number2)
elif number2 == number3 :
if number2 > number1 :
print(number2, 'and' ,number3, 'are greater than ',number1)
else :
print(number1, 'is greater than ',number2, 'and' ,number3)
elif number1 == number3 :
if number1 > number2 :
print(number1, 'and' ,number3, 'are greater than ',number2)
else :
print(number2, 'is greater than ',number1, 'and' ,number3)
elif number1 > number2 and number1 > number3 :
print(number1, 'is greater than ',number2, 'and' ,number3)
elif number2 > number1 and number2 > number3 :
print(number2, 'is greater than ',number1, 'and' ,number3)
elif number3 > number1 and number3 > number2 :
print(number3, 'is greater than ',number1, 'and' ,number2)
Running Code :

Output

Input

Output
Ques 7. Write a program to determine whether a number is prime or
composite.
Code :

number = int(input('Enter a Number : ')) #input a number


i = 2

while i < number : # determine whether it is prime or not


if number % i == 0 :
print(number, 'is not a prime number')
break
i += 1
else :
if number == 1 or number == 0 :
print(number, 'is neither a prime number nor a composite
number')
else :
print(number, 'is a prime number')

Running Code :

Input

Output
Ques 8. Write a program to get the sum of this series 1 + x + x**2 + x**3 +
x**4 + ..... + x**n .

Code :

n = int(input('Enter the value of n : '))# input two values


x = int(input('Enter the value of x : '))
tsum = 0
i = 0
while i <= n : # using loop to get sum of the series
tsum += x**i
i += 1
print('Sum of this series 1 + x + x**2 + x**3 + x**4 + ..... + x**n
where n =',n, 'and x =',x, 'is', tsum)

Running Code :

Input

Output
Ques 9. Write a program to get the sum of this series 1 – x + x**2 - x**3 +
x**4 + ..... + x**n .

Code :

n = int(input('Enter the value of n : ')) #input the value of x, n


x = int(input('Enter the value of x : '))
tsum = 0
i = 0
while i <= n : # loop to get the sum of series
if i % 2 == 0 :
tsum += x**i
else :
tsum -= x**i
i += 1
print('Sum of this series 1 - x + x**2 - x**3 + x**4 + ..... + x**n
where n =',n, 'and x =',x, 'is', tsum)

Running Code :

Input

Output
Ques 10. Write a program to determine the sum of the series x - x**2/2 +
x**3/3 - x**4/4 + ........... + x**n/n.

Code :

n = int(input('Enter the value of n : ')) # input the value of n, x


x = int(input('Enter the value of x : '))
tsum = 0
i = 1
while i <= n : #loop to get the sum of series
if i % 2 == 0 :
tsum -= x**i/i
else :
tsum += x**i/i
i += 1
print('Sum of this series x - x**2/2 + x**3/3 - x**4/4 + ...........
+ x**n/n where n =',n, 'and x =',x, 'is', tsum)

Running Code :

Input

Output
Ques 11. Write a program to get the sum of the series x + x**2/2! - x**3/3! +
x**4/4! + ........... + x**n/n! .
Code :

n = int(input('Enter the value of n : '))#input the value of n and x


x = int(input('Enter the value of x : '))
tsum = 0
i = 1
fact = 1
while i <= n :
if i >= 2:
f = i
while f > 1 :
fact *= f
f -= 1
if i % 2 == 0 or i==1 :
tsum += (x**i/fact)
else :
tsum -= (x**i/fact)
fact = 1
i += 1
print('Sum of this series x + x**2/2! - x**3/3! + x**4/4!
+ ........... + x**n/n! where n =',n, 'and x =',x, 'is', tsum)

Running Code :

Input

Output
Ques 12. Write the program to print the Pattern 12345
1234
123
12
1
Code :

n = int(input('Enter a Number : ')) # input a number

for i in range(n+1,1,-1) : # loop to print pattern


for j in range(1,i) :
print(j,end='')
print()

Running Code:

Input

Output
Ques 13. Write a program to print the pattern *
**
***
****
*****
Code :

n = int(input('Enter a Number : ')) # input a number

for i in range(n+1) : # loop to print pattern


for j in range(1,i+1) :
print('*',end='')
print()

Running Code :

Input

Output
Ques 14. Write a program to determine the greatest common divisor and
least common multiple.

Code :

n1 = int(input('Enter 1st number : ')) #input two numbers


n2 = int(input('Enter 2nd number : '))

gcd=0
for i in range(1,n1) : # finding th Greatest common divisor
if n1 % i == 0 and n2 % i == 0 :
gcd = i
lcm = n1*n2/gcd # finding the Least common multiple

print('Greatest Common Divisor of (%d,%d) is %d' %(n1,n2,gcd))


print('Least Common Multiple of (%d,%d) is %d' %(n1,n2,lcm))

Running Code :

Input

Output
Ques 15. Write a program to determine how many vowels, consonants,
uppercase, and lowercase are present in the text.

Code :

txt = input("Enter Your Text : ") #input a text


v = c = uc = lc = 0
v_list = ['a','e','i','o','u']
for i in txt: #finding the vowels, consonants , uppercase and
lowercase
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, Consonants, Uppercase and Lowercase in
the', txt, 'are as follows respectively :', v,',', c,',', uc,',',
'and', lc)

Running Code :

Input Output
Ques 16. Display the terms of the Fibonacci series.

Code :

n = int(input('Enter the no. of term you want to display : '))


n1=0
n2=1
i=0
if n==0 :
print('there are zero terms of Fibonacci series, please try
again !')
elif n < 0 :
print('please enter a positive value')
else :
print('Fibonacci series :',end=' ')
while i < n:
print(n1,',',end=' ')
nth = n1 +n2
n1 = n2
n2=nth
i += 1

Running Code :

Input

Output
Ques 17. Input a string and determine whether it is a palindrome or not.

Code:

txt = str(input('Enter a String : '))


n = len(txt)
i = 0
while i <= n : # loop to get whether it is a Palindrome
if txt[i] != txt[n-i-1]:
print('No! ',txt,' is not a Palindrome')
break
elif i > n/2 :
print('Yes! ,',txt,' is a Palindrome')
break
else:
i+=1

Running Code :

Input

Output
Ques 18. Convert the case of characters in a string.

Code :

txt = str(input('Enter a string : ')) #input a string

print('Converted the case of string :')


print(txt.swapcase())#use the swapcase function of string

Running Code :

Input

Output
Ques 19. Write a program to print the pattern A
AB
ABC
ABCD

ABCDE
Code :

n = int(input('Enter a number : ')) # enter a number

for i in range(1,n+1):
a = 65 #ord of A is 65
for j in range(1,i+1) :
print(chr(a),end='')
a+=1
print()

Running Code :

Input

Output
Ques 20. Convert Celsius to Fahrenheit or visa versa.

Code :

print('1. Fahrenheit') #ask user in which measurement he/she wants


print('2. Celsius')
n = int(input('Enter a number : '))

if n == 1: # convert it
c = int(input('Enter temperature in Celsius : '))
f = 9*c/5+32
print('Temperature in Fahrenheit is ',f,'°F')
elif n == 2 :
f = int(input('Enter Temperature in Fahrenheit : '))
c = 5/9*(f - 32)
print('Temperature in Celsius is ',c,'°C')
else:
print('It seem to be that you have entered wrong input')

Running Code :

Input

Output

Ques 21. Write a program which tells about how many alphabets, digit,
lowercase and uppercase characters are present in a sentence.
Code :

txt = input('Enter a sentence : ') # input a sentence

alpha = 0
digit = 0
lower = 0
upper = 0
for i in txt : # check how following things are present
if i.isalpha() :
alpha += 1
elif i.isdigit() :
digit +=1
if i.islower() :
lower+=1
if i.isupper():
upper+=1
print('there are the following in the sentence :')
print('Alphabet : ',alpha)
print('Digit : ',digit)
print('lowercase : ',lower)
print('Uppercase : ',upper)
print('The lenght of the sentence is : ',len(txt))

Running Code :

Input

Output

Ques 22. Write a program to remove all the vowels from the sentence or
string.
Code :

txt = str(input('Enter a sentence : '))# input a string

str1 = ''

for i in range(0,len(txt)) : # removing all vowels


if txt[i] not in 'aeiouAEIOU' :
str1 = str1 + txt[i]
print('After removing all the vowels the sentence will be :')
print(str1)

Running Code :

Input
Output

You might also like