2022-23
NAME:
ROLL NO:
CLASS: XI
STREAM:
NERUL, NAVI MUMBAI
CERTIFICATE
This is to certify that this computer practical file has
been completed by ____________________ of class XI
Science/Commerce, in partial fulfillment of the
curriculum of the Central Board of Secondary
Education leading to the award of All India Senior
School Certificate for the year 2022-23.
Roll No. :
__________________
Internal Examiner
Date:
__________________ ___________________
SCHOOL SEAL PRINCIPAL
Date:
SR. PROGRAM DAT PAG TEACHERS
SIGNATUR
NO E E E&
. NO. REMARKS
WAP to Input a welcome message and
01.
display it.
WAP to Input two numbers and display the
02.
smaller number.
Write Python program to print the area of
03. circle when radius of the circle is given by
user.
Write Python program that accepts marks in
04.
5 subjects and outputs average marks.
Write a short program that asks for your
height in centimetres and then converts
05.
your height to feet and inches. (1 foot = 12
inches, 1 inch = 2.54 cm).
Write Python program to compute simple
06.
interest and compound interest.
Write Python program to calculate the Area
07.
of a Triangle(given base and height)
WAP to Input three numbers and display the
08.
largest number.
WAP to Generate the following pattern using
nested loop.
*
09.
**
***
****
*****
WAP to Generate the following pattern using
nested loop.
10. 1
123
1234
12345
WAP to generate the following pattern using
nested loop.
A
11. AB
ABC
ABCD
ABCDE
WAP to input the value of x and n and print
the sum of the following series
12.
WAP to Determine whether a number is a
13.
perfect number.
WAP to determine whether a number is an
14.
armstrong number.
WAP to determine whether a number is a
15. palindrome.
WAP to Input a number and check if the
16. number is a prime or composite number.
Write a Program in Python to find the GCD &
17. WAP to Display the terms of a Fibonacci
series.
WAP to compute the greatest common
divisor and least common multiple of two
18.
integers.
WAP to Count and display the number of
vowels, consonants, uppercase, lowercase
19.
characters in string.
WAP to Input a string and determine
20.
whether it is a palindrome or not.
WAP to check the given year is leap year or
21.
not
WAP to print the following series:
22.
(i) 1 4 7 10. . . . . . . 40
(ii) 1 -4 7 -10 . . . . . . . - 40
WAP to find the factorial of a number
23.
Write a Menu-Driven Program to create a
24.
simple calculator
25.
PYTHON PROGRAMS
1. WAP to Input a welcome message and display it.
Code:
msg=input("Enter a welcome message"))
print(msg)
SAMPLE OUTPUT:
2. WAP to Input two numbers and display the smaller number.
Code:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
if (num1 < num2):
print("The smallest number is", num1)
else:
print("The smallest number is", num2)
SAMPLE OUTPUT:
3. Write Python program to print the area of circle when radius
of the circle is given by user.
Code:
radius=float(input("Enter radius of circle"))
PI=3.14
area = PI*radius**2
print("The area of circle is: ", area)
SAMPLE OUTPUT:
4. Write Python program that accepts marks in 5 subjects and
outputs average marks.
Code:
sub1=int(input("Enter marks of the first subject: "))
sub2=int(input("Enter marks of the second subject: "))
sub3=int(input("Enter marks of the third subject: "))
sub4=int(input("Enter marks of the fourth subject: "))
sub5=int(input("Enter marks of the fifth subject: "))
avg=(sub1+sub2+sub3+sub4+sub4)/5
print("The average of 5 subjects is ", avg)
SAMPLE OUTPUT:
5. Write a short program that asks for your height in
centimetres and then converts your height to feet and inches. (1
foot = 12 inches, 1 inch = 2.54 cm).
Code:
h = float(input('Enter your height in centimetres : '))
h = h/2.54 # height in inches
print('Height is', h//12, 'feets and', h%12, 'inches')
SAMPLE OUTPUT:
6. Write Python program to compute simple interest and
compound interest.
Code:
#simple interest
P = float(input("enter amount"))
R = float(input("enter rate"))
T = float(input("enter time"))
SI = (P * R * T) / 100
print("simple interest is", SI)
#Compound Interest
principle=float(input("Enter principle amount:"))
time=int(input("Enter time duration:"))
rate=float(input("Enter rate of interest:"))
amount = (principle * (1 + (float(rate)/100))**time)
compound_interest=amount-principle
print("Total amount:- ",amount)
print("Compound interest:- ",compound_interest)
SAMPLE OUTPUT:
7. Write Python program to calculate the Area of a
Triangle(given base and height)
Code:
b = float(input('Enter base of a triangle: '))
h = float(input('Enter height of a triangle: '))
area = (b * h) / 2
print('The area of the triangle is %0.2f' % area)
SAMPLE OUTPUT:
8. WAP to Input three numbers and display the largest number.
Code:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))
if (num1 >= num2) and (num1 >= num3):
largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3
print("The largest number is", largest)
SAMPLE OUTPUT:
9. WAP to Generate the following pattern using nested loop.
*
**
***
****
*****
Code:
n=int(input("Enter a no"))
for i in range(0, n): # outer loop
for j in range(0, i+1): #inner loop
# printing stars
print("*",end="")
# ending line after each row
print("\r")
SAMPLE OUTPUT:
10. WAP to Generate the following pattern using nested loop.
1
123
1234
12345
Code:
n=int(input("Enter a no"))
for i in range(1, n+1): # outer loop
for j in range(1, i+1): #inner loop
print(j,end=" ")
# ending line after each row
print("\r")
SAMPLE OUTPUT:
11. WAP to generate the following pattern using nested loop.
A
AB
ABC
ABCD
ABCDE
Code:
n=int(input("Enter the range"))
for i in range(1, n+1): # outer loop
val=65
for j in range(1, i+1): #inner loop
print(chr(val),end=" ")
val=val+1
# ending line after each row
print("\r")
SAMPLE OUTPUT:
12. WAP to input the value of x and n and print the sum of the
following series:
Code:
Series 1:
x = float (input ("Enter value of x :"))
n = int (input ("Enter value of n :"))
s=1
for a in range (1, n + 1) :
s += x**a
print ("Sum of series", s)
Series 2:
x = float (input ("Enter value of x :"))
n = int (input ("Enter value of n :"))
s=1
for a in range (1, n + 1) :
if a%2==0:
s += x**a
else:
s -= x**a
print ("Sum of series", s)
Series 3:
x = float (input ("Enter value of x :"))
n = int (input ("Enter value of n :"))
s=0
for a in range (1, n + 1) :
if a%2==0:
s += (x**a)/a
else:
s -= (x**a)/a
print ("Sum of series", s)
Series 4:
x = float (input ("Enter value of x :"))
n = int (input ("Enter value of n :"))
s=0
fact=1
for a in range (1,n + 1) :
fact=fact*a
if a%2==0:
s += (x**a)/fact
else:
s -= (x**a)/fact
print ("Sum of series", s)
SAMPLE OUTPUT:
13. WAP to Determine whether a number is a perfect number.
Code:
n = int(input("Enter any number: "))
sum1 = 0
for i in range(1, n):
if(n % i == 0):
sum1 = sum1 + i
if (sum1 == n):
print("The number is a Perfect number!")
else:
print("The number is not a Perfect number!")
SAMPLE OUTPUT:
14. WAP to determine whether a number is an armstrong
number.
Code:
import math
print ("Enter the a number")
number = int(input())
#to calculate the number of digits in a number
number_of_digits = int(math.log10(number))+1
sum_arm = 0
temp = number
while temp != 0:
sum_arm = sum_arm + int([Link] (temp%10,number_of_digits))
temp = temp//10
if sum_arm == number:
print ("Yes an Armstrong number")
else:
print ("No")
SAMPLE OUTPUT:
15. WAP to determine whether a number is a palindrome.
Code:
n=int(input("Enter number:"))
temp=n
rev=0
while(n>0):
dig=n%10
rev=rev*10+dig
n=n//10
if(temp==rev):
print("The number is a palindrome!")
else:
print("The number isn't a palindrome!")
SAMPLE OUTPUT:
16. WAPto Input a number and check if the number is a prime
or composite number.
Code:
import math
print ("Enter the a number")
number = int(input())
i=2
prime = True
#if the number is not divisible by any number less than the
#square root of the number
#then it is prime
while i <= int([Link](number)):
if number%i == 0:
prime = False
break
i = i+1
if number < 2:
prime = False
if prime:
print (number,"is a prime number")
else:
print (number,"is not a prime number")
SAMPLE OUTPUT:
17. WAP to Display the terms of a Fibonacci series.
Code:
Number = int(input("\nPlease Enter the Range Number: "))
# Initializing First and Second Values of a Series
First_Value = 0
Second_Value = 1
# Find & Displaying Fibonacci series
for Num in range(0, Number):
if(Num <= 1):
Next = Num
else:
Next = First_Value + Second_Value
First_Value = Second_Value
Second_Value = Next
print(Next)
SAMPLE OUTPUT:
18. WAP
to compute the greatest common divisor and least
common multiple of two integers.
Code:
def gcd(x,y):
if(y==0):
return x
else:
r=x%y
return(gcd(y,r))
def lcm(x,y):
p=x*y
l=p/gcd(x,y)
return l
x=int(input("Enter the larger No.: "))
y=int(input("Enter the smaller No.: "))
print("GCD is",gcd(x,y))
print("LCM is",lcm(x,y))
SAMPLE OUTPUT:
19. WAPto Count and display the number of vowels, consonants,
uppercase, lowercase characters in string.
Code:
string = input("Enter Your String : ")
vowels = consonants = uppercase = lowercase = 0
vowels_list = ['a','e','i','o','u',’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 [Link]():
uppercase += 1
if [Link]():
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)
SAMPLE OUTPUT:
20. WAP to Input a string and determine whether it is a
palindrome or not.
Code:
string=input(("Enter a string:"))
if(string==string[::-1]):
print("The string is a palindrome")
else:
print("Not a palindrome")
SAMPLE OUTPUT:
21. WAP to check the given year is leap year or not
Code:
year = int(input("Enter a year: "))
if (year % 4) == 0:
if (year % 100) == 0:
if (year % 400) == 0:
print("{0} is a leap year".format(year))
else:
print("{0} is not a leap year".format(year))
else:
print("{0} is a leap year".format(year))
else:
print("{0} is not a leap year".format(year))
SAMPLE OUTPUT:
22. WAP to print the following series:
(i) 1 4 7 10. . . . . . . 40
(ii) 1 -4 7 -10 . . . . . . . - 40
Code:
print("First Series:")
for i in range(1, 41, 3) :
print(i, end = ' ')
print("\nSecond Series:")
x=1
for i in range(1, 41, 3) :
print(i * x, end = ' ')
x *= -1
SAMPLE OUTPUT:
23. WAP to find the factorial of a number
Code:
n=int(input("Enter number:"))
fact=1
while(n>0):
fact=fact*n
n=n-1
print("Factorial of the number is: ")
print(fact)
SAMPLE OUTPUT:
24. Write a Menu-Driven Program to create a simple calculator
Code:
# Menu-Driven Program to create a simple calculator
print("WELCOME TO A SIMPLE CALCULATOR")
# using the while loop to print menu list
while True:
print("\nMENU")
print("1. Sum of two Numbers")
print("2. Difference between two Numbers")
print("3. Product of two Numbers")
print("4. Division of two Numbers")
print("5. Exit")
choice = int(input("\nEnter the Choice: "))
# using if-elif-else statement to pick different options
if choice == 1:
print( "\nADDITION\n")
a = int( input("First Number: "))
b = int( input("Second Number: "))
sum = a + b
print(a, "+", b, "=", sum)
elif choice == 2:
print( "\nSUBTRACTION\n")
a = int( input("First Number: "))
b = int( input("Second Number: "))
difference = a - b
print(a, "-", b, "=", difference)
elif choice == 3:
print( "\nMULTIPLICATION\n")
a = int( input("First Number: "))
b = int( input("Second Number: "))
product = a * b
print(a, "x", b, "=", product)
elif choice == 4:
print( "\nDIVISION\n")
a = int( input("First Number: "))
b = int( input("Second Number: "))
division = a / b
print(a, "/", b, "=", division)
elif choice == 5:
break
else:
print( "Please Provide a valid Input!")
SAMPLE OUTPUT:
25. Write a Program to take in the marks of 5 subjects and display
the grade.
Code:
sub1=int(input("Enter marks of the first subject: "))
sub2=int(input("Enter marks of the second subject: "))
sub3=int(input("Enter marks of the third subject: "))
sub4=int(input("Enter marks of the fourth subject: "))
sub5=int(input("Enter marks of the fifth subject: "))
avg=(sub1+sub2+sub3+sub4+sub4)/5
if(avg>=90):
print("Grade: A")
elif(avg>=80 and avg<90):
print("Grade: B")
elif(avg>=70 and avg<80):
print("Grade: C")
elif(avg>=60 and avg<70):
print("Grade: D")
else:
print("Grade: F")
SAMPLE OUTPUT: