Class Xii CS Practical File 2
Class Xii CS Practical File 2
alternatively
INPUT=
OUTPUT=
OUTPUT=
PROGRAM 3 - Write a program to enter Username and code,
where the code can’t have the username ,and it should
have at least 5 characters for registration
OUTPUT=i)
ii)
iii)
OUTPUT=
OUTPUT=
OUTPUT=
OUTPUT=
OUTPUT=
OUTPUT=
INPUT=
OUTPUT=
OUTPUT=
def removevowel(str1):
str2=str1
for i in str1:
if i in "AEIOUaeiou":
str2=str2.replace(i," ")
print("The string after removal of all vowels is:",str2)
str1=input("Enter string")
removevowel(str1)
def search(list,n):
for i in range(len(list)):
if list[i]==n:
return i
return -1
L=[ ]
for i in range(1,11):
a=int(input("enter numbers"))
L.append(a)
N=int(input("enter number to be found"))
result=search(L,N)
if result==-1:
print("not found")
else:
print("element"+str(N)+"is found at position",result+1)
def insertionsort(arr):
for i in range(1,len(arr)):
value=arr[i]
pos=i
while pos>0 and value<arr[pos-1]:
arr[pos]=arr[pos-1]
pos=pos-1
arr[pos]=value
L=[ ]
for i in range(1,11):
a=int(input("enter numbers"))
L.append(a)
i=1
print("Original List:",L)
insertionsort(L)
print("sorted list:",L)
def bubblesort(arr):
n=len(arr)
for i in range(n-1):
for j in range(n-i-1):
if arr[j]>arr[j+1]:
arr[j],arr[j+1]=arr[j+1],arr[j]
n=int(input("enter number of elements"))
L=[]
for i in range (n):
a=int(input("enter numbers"))
L.append(a)
print("original list:",L)
bubblesort(L)
print("sorted list:",L)
OUTPUT:
2.WAPP to demonstrate all methods applicable on strings .’’’
#ARZA KAUR S7C
OUTPUT:
3.‘WAPP to input annual income of a person and calculate the payable
income’’’
#ARZA KAUR S7C
if EC<=200:
BILL=0
elif EC<=400:
BILL=600+ 4.5*(EC-200)
elif EC<=800:
BILL= 1500 + 6.5*(EC-400)
elif EC<=1200:
BILL= 2800 + 7*(EC-800)
else:
BILL=4200+ 7.75*(EC-1200)
print("The total bill = ", BILL)
def fibonacci_numbers(num):
if num == 0:
return 0
elif num == 1:
return 1
else:
return fibonacci_numbers(num-2)+fibonacci_numbers(num-1)
n=7
for i in range(0, n):
print(fibonacci_numbers(i), end=" ")
RESTART: C:/Users/ShuntyAnand/AppData/Local/Programs/Python/Python36/non.py
0112358
>>>
6.‘‘‘WAPP to input a natural number and display all the FACTORS of that number’’’
#ARZA KAUR S7C
7.‘‘‘WAPP to input a natural number and check whether the number is a PRIME or
not.’’’
#ARZA KAUR S7C
for i in range(2,N):
if (N%i==0):
SUM+=1
if (SUM==0):
print("The number is prime.")
else:
print("The number is not prime.")
9.‘‘‘WAPP to input two natural numbers and check whether they are CO-PRIME or
not.’’’
#ARZA KAUR S7C
10.‘‘‘WAPP to input two natural numbers and calculate and display their LCM.’’’
#ARZA KAUR S7C
A=int(input("Enter the first natural number : "))
B=int(input("Enter the second natural number : "))
LCM=0
for i in range(A,(A*B)+1):
if (i%A==0)and (i%B==0):
LCM=i
if (LCM>=A):
break
print("The LCM = ", LCM)
12.‘‘‘ *
**
***
* * * *.’’’
#ARZA KAUR S7C
N=int(input("Enter a natural number : "))
for i in range(1,N+1):
print(“*’*i)
RESTART: C:/Users/Shunty Anand/AppData/Local/Programs/Python/Python36/non.py
Enter a natural number : 4
*
**
***
****
>>>
13.‘‘‘ 1
12
123
1234
.’’’
#ARZA KAUR S7C
14.‘‘‘ *
***
*****
* * * * * * *.’’’
#ARZA KAUR S7C
def ISPERFECT(N):
SUM=0
for i in range(1,(N//2)+1):
if N%i==0:
SUM+=i
if SUM==N:
return True
else:
return False
for i in range(1,1001):
if ISPERFECT(i):
print(i)
RESTART: C:/Users/Shunty Anand/AppData/Local/Programs/Python/Python36/non.py
6
28
496
def POW(X,N):
return X**N
def FACTORIAL(N):
P=1
for i in range(1,N+1):
P*=i
return P
n=int(input("n = "))
x=float(input('x= '))
S1,S2,S3,S4=1,1,x,x
for i in range(1,n+1):
S1+=POW(x,i)
S2+=(POW(x,i)*POW(-1,i))
for i in range(2,n+1):
S3+=(POW(x,i)/i * POW(-1,i))
S4+=(POW(x,i)/FACTORIAL(i) * POW(-1,i))
print('The sum of series 1 + x^1 + X^2 + x^3 +... + x^n = ', S1)
print('The sum of series 1 - x^1 + X^2 - x^3 +... +or- x^n = ', S2)
print('The sum of series x^1/1 + X^2/2 - x^3/3 +... +or- x^n = ', S3)
print('The sum of series x^1/1 + X^2/2 - x^3/3 +... +or- x^n =', S4)
RESTART: C:/Users/Shunty
Anand/AppData/Local/Programs/Python/Python36/non.py
N=4
X =2
'The sum of series 1 + x^1 + X^2 + x^3 +... + x^n = 31.0
'The sum of series 1 - x^1 + X^2 - x^3 +... +or- x^n= 11.0
'The sum of series x^1/1 + X^2/2 - x^3/3 +... +or- x^n =
5.3333333334
'The sum of series x^1/1 + X^2/2 - x^3/3 +... +or- x^n =
3.3333333333335
17.Define a recursive function Factorial(N) to calculate and return
factorial of N. Write a program
to display factorial of the first 5 natural numbers.
'''
#ARZA KAUR S7C
def FACTORIAL(N):
P=1
for i in range(1,N+1):
P*=i
return P
print(FACTORIAL(5))
RESTART: C:/Users/Shunty
Anand/AppData/Local/Programs/Python/Python36/non.py
18.Write a menu based program to perform the following task on a Python List
NUMBERS.
A sample List NUMBERS = [12, 33, 13, 54, 34, 57]
The tasks are:
i) Add a new number in the List NUMBERS, entered by the user
ii) Display all numbers stored in the List NUMBERS
iii) Sort the List NUMBERS in descending order using bubble sort technique
(define a function).
'''
#ARZA KAUR S7C
def SORT(L):
for i in range(len(L)-1):
for j in range(len(L)-i-1):
if L[j]<L[j+1]:
temp=L[j+1]
L[j+1]=L[j]
L[j]=temp
return L
while True:
CHOICE=input('Enter your choice : ')
if CHOICE=='1':
X=int(input('Enter the new no. : '))
I=int(input('Enter the index no. where it needs to be inserted : '))
NUMBERS.insert(I,X)
elif CHOICE=='2':
print(NUMBERS)
elif CHOICE=='3':
SORT(NUMBERS)
elif CHOICE=='4':
print('Thank you')
break
else:
print('Invalid choice.')
OUTPUT:
19.Write a menu based program to perform the following task on a Python List
WORDS.
A sample List WORDS = ['LAN', 'MAN', 'WAN', 'VoIP', 'HTTPS']
The tasks are:
i) Add a new word in the List WORDS, entered by the user
ii) Display all words stored in the List WORDS
iii) Sort the List WORDS alphabetically using bubble sort technique (define a
function)
'''
#ARZA KAUR S7C
def SORT(L):
for i in range(len(L)-1):
for j in range(len(L)-i-1):
if L[j]>L[j+1]:
temp=L[j+1]
L[j+1]=L[j]
L[j]=temp
return L
while True:
CHOICE=input('Enter your choice : ')
if CHOICE=='1':
X=int(input('Enter the new no. : '))
I=int(input('Enter the index no. where it needs to be inserted : '))
NUMBERS.insert(I,X)
elif CHOICE=='2':
print(NUMBERS)
elif CHOICE=='3':
SORT(NUMBERS)
elif CHOICE=='4':
print('Thank you')
break
else:
print('Invalid choice.')
OUTPUT:
def SEPARATE(NUMBERS):
for ele in NUMBERS:
if ele%2==0:
EVEN.append(ele)
else:
ODD.append(ele)
return EVEN,ODD
print(NUMBERS) #(ii)
EVEN,ODD=SEPARATE(NUMBERS) #(iii)
print('EVEN NUMBERS:', tuple(EVEN))
print('ODD NUMBERS: ', tuple(ODD))
OUTPUT:
TERM 1 PROGRAMS
TASK-1-WAPP to display the nature of roots of a Quadratic Equation.
TASK-2-WAPP to read 3 sides (or angles) of a triangle and display whether it’s a Valid Triangle.
TASK-3-WAPP to input a natural number and display the MULTIPLICATION TABLE of that number.
TASK-6-WAPP to input two natural numbers and check whether those numbers are AMICABLE or
not.
TASK-7-WAPP to input two natural numbers and calculate and display their HCF/GCD
TASK-8- Write Python programs to input a floating number x and a natural number n and calculate
and display the sum of the cosine series'
TASK-9- Write Python programs to input a floating number x and a natural number n and calculate
and display the sum of the sine series
TASK-10-'''Write Python programs to input a natural number N (if N=4) and display the following
PATTERN:
**
***
****
TASK-11-Write Python programs to input a natural number N (if N=4) and display the following
PATTERN:
12
123
1234
TASK-12-'''Write Python programs to input a natural number N (if N=4) and display the following
PATTERN:
***
*****
******
TASK-13-'''Write Python programs to input a natural number N (if N=4) and display the following
PATTERNS
121
12321
1234321'''
TASK-14- WAPP to input a natural number N and calculate & display the FACTORIAL of N.
TASK-15- WAPP to input a natural numbers and check whether the number is PALINDROMIC or not.
FUNCTION BASED PROGRAMS
TASK-1-Define a function Pattern(N) to display the following pattern when N=4:
TASK-2- Define a function isPerfect(N) to check whether N is a perfect or not. If perfect, the function
should return 1 otherwise 0. Using the defined function, write a program to display all perfect
numbers between 1 and 1000.
TASK-5-Define a function isPrime(N) to check whether N is a prime or not. If prime, the function
shouldReturn 1 otherwise 0. Using the defined function, write a program to display all prime
TASK-7-Define a function SumOfFactors(N) to calculate and return sum of all proper factors of N
(allfactors including 1 and excluding the number N itself). Using the defined function, write a
program to check whether a number M is perfect or not.
TASK-8- Define a function SumOfFactors(N) to calculate and return sum of all proper factors of N (all
factors including 1 and excluding the number N itself). Using the defined function, write a program
to check whether 2 numbers A and B are amicable or not.
TASK-9- Define a recursive function Factorial(N) to calculate and return factorial of N. Write a
program to display factorial of the first 5 natural numbers.
TASK-10-.Define a recursive function Fibonacci(N) to calculate and return Nth member of the
Fibonacci number series. Write a program to display the first 20 Fibonacci numbers.
STRING/TUPLE/LIST/DICTIONARY BASED
PROGRAMS
TASK-11-WAPP to read a name and display the initials separated by periods.
TASK-12-WAPP to read a name and display the initials of all words except last name and the full last
name separated by periods.
TASK-13-WAPP to read a string and count number of uppercase characters, lowercase characters
and special characters.
TASK-14- WAPP to read a sentence and display the same by reversing characters of all words without
changing the sequence of the words.
TASK-15- WAPP to read a sentence and check whether that sentence contains a word entered by the
user (with or without case sensitivity)
TASK-16- WAPP to input an amount of money and display MINIMUM CURRENCY NOTES (out of
2000/500/200/100/50/20/10/5/2/1) required to have that money.
TASK-17- WAPP to process menu based following operations on a Python LIST having
Create/Append/Display/Search/Modify/Delete.
TASK-18-WAPP to process STACK (LIFO) operations on a Python LIST of numbers [TOP is at the end of
the main LIST)
TASK-19- WAPP to process QUEUE (FIFO) operations on a Python LIST of names
TASK-20-WAPP to read a Python List having 10 Country names and display only those which are 6 or
more characters long.
TASK-21- WAPP to read a Python LIST-STUDENTS contains some small LISTs storing names and
respective marks of few students. Read a name from the user and allow the user to edit their marks.
TASK-22-WAPP to create a Python LIST-STUDENTS contains 10 small LISTS storing names and
respective marks of few students. Read a name from the user and display the marks of that student
TASK-23-WAPP to create a Python LIST-STUDENTS contains 10 small LISTS storing names and
respective marks of few students. Count and display only the number of students who have passed
(scored >=33) and failed.
TASK-24-WAPP to read a List having 10 names and display only those which ends with consonants.
TASK-25-WAPP to read a LIST of numbers and create 2 separate LISTS PRIME and COMPOSITE
TASK-26- WAPP to read a List having 10 names and display only those which ends with consonants.
TASK-27-WAPP to add user entered elements to a tuple and finally display it
TASK-29-WAPP to add user entered element to tuple of numbers, sort the tuple, or display it using a
menu.
TASK-30-WAPP to show names of people over 25 in given tuple of tuples AGES.
TASK-31- WAPP to store a menu in the form of a dictionary with product name as key and price as
value
TASK-32- WAPP to show names of people earning 10000 Rs or more a month from dictionary
containing names as keys and salaries in Rs as values.
Task-33-WAPP to accept employee id from user and store employee name and employee salary in a
dictionary of the format ID: (Name, Salary)
TASK-34-WAPP to create a frequency table of words in a sentence given by user using dictionary
TASK-35- WAPP to see if employee salary is less than 25000 in dictionary of format ID:(Name,Salary)
and increment salary by 1000 if it is. Also display names of those with unchanged salary.