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

Practical File Solutions

Uploaded by

himankdholpuriab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

Practical File Solutions

Uploaded by

himankdholpuriab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

PM SHRI KENDRIYA VIDYALAYA NO.

2 CPE ITARSI
CLASS-XI
COMPUTER SCIENCE (083)
PRACTICAL FILE [2024-25)

Programming Language – Python

Program#1: Write a program to input a welcome message and display it.


# Program to input a welcome message and display it
name=input("Enter your name :")
print("Hello”, name, “Welcome to the world of Python”)

Program#2: Write a program that takes the length and breadth of a


rectangle from the user and calculate and prints its area and perimeter.
# Program to calculate the area of a rectangle
l = float(input("Enter length of the rectangle :"))
b = float(input("Enter breadth of the rectangle :"))
area = l*b
print("Area of the rectangle is :",area)

Program#3: Write a program to input two numbers and display the larger/
smaller number.
# Program to display the larger of two numbers
Num1 = int(input("Enter the first number :"))
Num2= int(input("Enter the second number :"))
if Num1>Num2:
print(Num1, “is larger”)
else:
print(Num2, “is larger”)

Program#4: Write a program to input three numbers and display the


largest/ smallest number.
# Program to display the largest of three numbers
num1 = int(input("Enter the First number: "))
num2 = int(input("Enter the Second number: "))
num3 = int(input("Enter the Third number: "))
if num1 > num2 and num1 > num3:
print(num1," is the largest number”)
elif (num2 > num1 and num2 > num3):
print(num2," is the largest number”)
elif (num3 > num1 and num3 > num2):
print(num3," is the largest number”)
else:
print("Either any two values or all the three values are equal")

Program#5: Write a program to enter the marks of a student in 5


subjects, calculate the percentage and assign grade as follows:
Percentage range Grade assigned
percent>=75 A
65<=percent<75 B
50<=percent<65 C
percent<50 D

1
# Program to calculate percentage and assign grade
print("Enter the marks of the student in 5 subjects out of 100")
sub1= int(input("Enter marks in subject1 :"))
sub2= int(input("Enter marks in subject2 :"))
sub3= int(input("Enter marks in subject3 :"))
sub4= int(input("Enter marks in subject4 :"))
sub5= int(input("Enter marks in subject5 :"))
per = (sub1+sub2+sub3+sub4+sub5)/5
if per>=75:
grade = 'A'
elif per>=65 and per<75:
grade = 'B'
elif per>=50 and per<65:
grade = 'C'
else:
grade = 'D'
print("Percentage scored = ",per,"%", "Grade = ", grade)

Program#6: Write a program to generate the following patterns using


nested loops:
Pattern-1 Pattern-2 Pattern-3
* 1 2 3 4 5 A
* * 1 2 3 4 A B
* * * 1 2 3 A B C
* * * * 1 2 A B C D
* * * * * 1 A B C D E

#Pattern-1
n = int(input(“Enter the no. of rows”))
for i in range(1, n+1):
for j in range(i):
print("*", end=" ")
print("\n")
print()

#Pattern-2
n = int(input(“Enter the no. of rows: ”))
for i in range(1, n+1):
for j in range(1, n+1):
print(j, end=" ")
print("\n")
n-=1
print()

#Pattern-3
n = int(input(“Enter the no. of rows: ”))
for i in range(1,n+1):
for j in range(65,65+i):
print(chr(j),end=' ')
print()

2
Program#7: Write a program to input the value of x and n and print the
sum of the following series:
1. 1+x + x² + x³ + … + xⁿ
2. 1-x + x² – x³ + … + xⁿ
𝐱² 𝐱³
3. x+ 𝟐 + 𝟑 + … + xⁿ
#Program to find the sum of series-1: 1+x + x² + x³ + … + xⁿ
x = float(input("Enter the value of x : "))
n = float(input("Enter the value of n : "))
sum = 0
for i in range(n+1):
sum = sum+ x**i
print("Sum of Series is :",sum)

#Program to find the sum of series-2: 1-x + x² – x³ + … + xⁿ


x = float(input("Enter the value of x : "))
n = float(input("Enter the value of n : "))
sum = 0
for i in range(n+1):
if i%2 == 0:
sum = sum+ x**i
else:
sum = sum - x**i
print("Sum of Series is :",sum)

𝐱² 𝐱³
#Program to find the sum of series-3: x+ 𝟐 + 𝟑 + … + xⁿ
x = float(input("Enter the value of x : "))
n = float(input("Enter the value of n : "))
sum = 0
for i in range(1, n+1):
sum = sum+ (x**i)/i
print("Sum of Series is :",sum)

Program#8: Write a program to find the sum of n natural numbers where n


is entered by the user.
# Program to find the sum of first n natural numbers
n = int(input("Enter the no. of terms: "))
s=0
for i in range(1,n+1):
s = s + i
print("Sum of first", n, "natural numbers is: ", s)

Program#9: Write a program to find the sum of digits of an integer


number entered by the user.
# Program to find the sum of digits of an integer number
num = int(input("Enter a positive integer>0: "))
s = 0
temp = num
while num > 0:
digit = num % 10
s = s + digit
num = num//10
print("Sum of digits of", temp, "is: ", s)

3
Program#10: Write a program to determine whether a number is a perfect
number or not.
[Note: a perfect number is a number that is half the sum of all of its
positive divisors (including itself)
Example: The first perfect number is 6, because 1,2 and 3 are its proper
positive divisors and (1+2+3+6)/6 = 6
Other Perfect numbers are: 28, 496, and 8128 etc]
# Program to check perfect number
num = int(input("Enter a positive integer>0: "))
s=0
for i in range(1,num):
if num%i==0:
s = s + i
if s == n:
print( n,"is perfect number")
else:
print( n, "is not perfect number")

Program#11: Write a program to determine whether a number is an


Armstrong number or not.
[Note: A number is called Armstrong number if it is equal to the sum of
the cubes of its own digits.
Example: 153 is an Armstrong number since 153 = 1*1*1 + 5*5*5 + 3*3*3
Other Armstrong numbers are: 370, 371, 407, and 1634 etc.]
# Program to check armstrong number
num = int(input("Enter a positive integer>0: "))
temp = num
s = 0
while num > 0 :
digit = num %10
s = s + (digit**3)
num = num//10
if temp == s:
print( temp,"is an Armstrong number")
else :
print( temp, "is not Armstrong number")

Program#12: Write a program to reverse a number and hence find whether


it is palindrome or not.
# Program to check palindrome number
num = int(input("Enter an integer number: "))
temp = num
rev = 0
while num > 0:
digit = num % 10
rev = rev *10 + digit
num = num//10
if temp == rev:
print(temp," is palindrome number")
else:
print(temp, "is not palindrome number")

4
Program#13: Write a program to input a number and check if the number is
prime or composite number.
#Program to check prime number
num= int(input("Enter a positive Integer>0: "))
if num == 1:
print(num," is neither prime nor composite")
elif num>1 :
for i in range(2,num//2+1):
if(num%i == 0):
print(num,"is not prime ")
break
else:
print(num," is prime")
else :
print("Please enter positive number only ")

Program#14: Write a program to generate the Fibonacci Series upto n


terms, where n is entered by the user.
#Program to generate Fibonacci Series upto n terms
# first two terms
t1 = 0
t2 = 1
term = int(input("Enter the number of terms : "))
if term <=0: # if number is negative or zero
print("Please enter a positive number only")
else:
print(n1,n2,end=" ")
for i in range(2,term):
n3 = n1+n2
print(n3,end=" ")
n1 = n2
n2 = n3

Program#15: Write a program to find the factorial of a number entered by


the user.
Note: [Factorial is a non-negative integer. It is the product of all
positive integers less than or equal to that number. It is denoted by !
(Exclamation) sign.
The factorial of a positive integer n is n! = n*(n-1)*(n-2) *........1
Example: 4! = 4x3x2x1 = 24]
#Program to find the factorial of a number
num = int(input("Enter a positive number to find factorial: "))
fact = 1
if num < 0:
print(" Factorial does not exist for negative numbers")
else:
for i in range(1,num + 1):
fact = fact*i
print("The factorial of",num,"is",fact)

5
Program#16: Write a program to compute the greatest common divisor and
least common multiple of two integers.
#Program to compute the GCD and LCM of two integers
x=int(input("Enter first number :"))
y=int(input("Enter Second number: "))
if x > y:
smaller = y
else:
smaller = x
for i in range(1, smaller+1):
if x % i == 0 and y % i == 0:
gcd = i
print('GCD of', x ,'and' ,y ,'is',gcd)
lcm=x*y/gcd
print('LCM of', x ,'and' ,y ,'is',lcm)

Program#17: Write a program to input a character and print whether the


given character is an alphabet, digit or any other character.
# Program to check character is Alphabet Digit or Special Character
ch = input("Enter a Character : ")
if((ch >= 'a' and ch <= 'z') or (ch >= 'A' and ch <= 'Z')):
print("The Given Character ", ch, "is an Alphabet")
elif(ch >= '0' and ch <= '9'):
print("The Given Character ", ch, "is a Digit")
else:
print("The Given Character ", ch, "is a Special Character")
OR
ch = input("Enter a Character : ")
if(ch.isdigit()):
print("The Given Character ", ch, "is a Digit")
elif(ch.isalpha()):
print("The Given Character ", ch, "is an Alphabet")
else:
print("The Given Character ", ch, "is a Special Character")

Program#18: Write a program to Count and display the number of vowels,


consonants, uppercase, lowercase characters in a string.
#Program to count number of vowels, consonants, uppercase & lowercase
char
str1=input("Enter any string: ")
v,u,l,w,c=0,0,0,0,0
for ch in str1:
if ch.islower():
l=l+1
if ch.isupper():
u=u+1
if ch.lower() in ['a','e','i','o','u']:
v=v+1
elif ch.isalpha():
c=c+1
print('Total number of Uppercase letters :',u)
6
print('Total number of Lowercase letters :',l)
print('Total number of Vowel :',v)
print('Total number of consonant :',c)

Program#19: Write a program to input a string and determine whether it


is palindrome or not; convert the case of characters in the string.
# Program to check if a string is palindrome or not
s = input("Enter any string :")
j = -1 #index of last element=-1
for i in s:
if i != s[j]:
print(s,"--> is not a palindrome string")
break
j = j - 1
else:
print(s,"--> is a palindrome string")
sc = s.swapcase()
print("String after case conversion: ",sc)
OR
s = input("Enter any string :")
j = len(s)-1 #index of last element
for i in range(len(s)):
if s[i] != s[j]:
print(s,"--> is not palindrome")
break
i = i + 1
j = j - 1
else:
print(s,"--> is a palindrome string")
print("String after case conversion: ", s.swapcase())

Program#20: Write a program to find the largest/ smallest item in a


given integer list/tuple
#Program to find the largest/smallest item in a given list
L=eval(input("Enter a list: "))
L.sort()
print("Min : ",L[0],"Max : ",L[len(L)-1])

or
L=eval(input("Enter a list: "))
print("Min : ",min(L),"Max : ",max(L))

or
L=eval(input("Enter a list: "))
Max=Min=L[0]
for i in range(1,len(L)):
if L[i]>Max:
Max=L[i]
if L[i]<Min:
Min=L[i]
print("Min : ",Min,"Max : ",Max)

7
Program#21: Write a program to display the second largest item in a
given list of integers.
#Program to find the second largest item from a given list
L =eval(input("Enter the list: "))
print("Original List:",L)
max1=max(L)
print(“Largest number is: ”,max1)
max2=L[0]
for i in range(1, len(L)):
if L[i]>max2 and L[i]<max1:
max2=L[i]
print("Second largest number is:",max2)

Program#22: Write a program to remove all even numbers from a given list
of integers.
#Program to remove all even numbers from a given list
L =eval(input("Enter the list: "))
print("Original List:",L)
for i in L:
if i%2==0:
L.remove(i)
print("Modified list: ",L)

Program#23: Write a program to input a list of numbers and swap elements


at the even location with the elements at the odd location.
# Program to swap elements at even locations with odd locations in a
list
L=eval(input("Enter the list:"))
print("Original List: ",L)
length=len(L)
if length%2!=0:
length=length-1
for i in range(0,length,2):
L[i],L[i+1]=L[i+1],L[i]
print("List after swap:",L)

Program#24: Write a program to input a list/tuple and search for given


element in the list/tuple.
#Program to input a list & search for given element in the list
L=eval(input("Enter the list:"))
item=int(input("Enter item to search:"))
print("Original List:",L)
for i in range(len(L)):
if L[i]==item:
print(item, “found at index: ”,i)
break
else:
print("Item not found in the list")

8
Program#25: Write a program to create a dictionary with roll number,
name and marks of n students in a class and display the names of
students who have scored marks above 75
# Program to create a dictionary for marks of n students
n = int(input("Enter number of students :"))
result = {}
for i in range(n):
print("Enter Details of students :",i+1)
rno = int(input("Enter Roll number :"))
name = input("Name :")
eng = float(input("Enter English Marks: "))
math = float(input("Enter Math Marks: "))
comp = float(input("Enter Computer Marks: "))
phy = float(input("Enter Physics Marks: "))
chem = float(input("Enter Chemistry Marks: "))
total = eng + math + comp + phy + chem
percentage = (total / 500) * 100
result[rno] = [name,percentage]
print(result)
for s in result:
if result[s][1]>75:
print("Following students having more than 75 marks:")
print(result[s][0])
else:
print(“None of the students scored marks>75”)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy