0% found this document useful (0 votes)
38 views8 pages

Yadav Saar GR 11 Cs Codes

The document lists various programming tasks for a Grade 11 Computer Science practical exam, including finding the sum of digits, checking for palindromes, calculating profit and loss, and identifying Armstrong and perfect numbers. Each task includes a brief description and a sample code solution. The tasks cover fundamental programming concepts and algorithms in Python.

Uploaded by

nithilan2305
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)
38 views8 pages

Yadav Saar GR 11 Cs Codes

The document lists various programming tasks for a Grade 11 Computer Science practical exam, including finding the sum of digits, checking for palindromes, calculating profit and loss, and identifying Armstrong and perfect numbers. Each task includes a brief description and a sample code solution. The tasks cover fundamental programming concepts and algorithms in Python.

Uploaded by

nithilan2305
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/ 8

List of Programs for Computer Science Practical Exam Grade 11

1 Write a program to find the sum of digits of an integer number, input by the user.
Do Not use string or string functions

Ans.

2 Write a function that checks whether an input number is a palindrome or not. [Note: A
number or a string is called palindrome if it appears same when written in reverse
order also. For example, 12321 is a palindrome while 123421 is not a palindrome]
Do Not use string or string functions

Ans.

3 Input CP, SP and calculate profit, % profit or loss, % loss or no profit no loss.

Ans. Cp= int(input("Enter Cost Price"))


Sp= int(input("Enter Selling Price"))
if Sp>Cp:
Profit= Sp-Cp
pp= (Profit/Cp)*100
print("Profit is ", Profit)
print("Profit percent is ", pp)
elif Cp>Sp:
Loss= Cp-Sp
pl= Loss/Cp*100
print("Loss is ", Loss)
print("Loss percent is ", pl)
else:
print("Neither profit nor loss")

4 # Check Armstrong Number: An Armstrong number (also known as a narcissistic


number, pluperfect number, or pluperfect digital invariant) is a number that is equal to
the sum of its own digits each raised to the power of the number of digits.
Example (3-digit number): 153
• Number of digits = 3
• Calculate:
13+53+33=1+125+27=1531^3 + 5^3 + 3^3 = 1 + 125 + 27 =
15313+53+33=1+125+27=153
• ✅ Since the result equals the original number, 153 is an Armstrong number

Example (4-digit number): 9474


• Number of digits = 4
• Calculate:
94+44+74+44=6561+256+2401+256=94749^4 + 4^4 + 7^4 + 4^4 = 6561 + 256 +
2401 + 256 = 947494+44+74+44=6561+256+2401+256=9474
• ✅ 9474 is an Armstrong number
Ans.

5 # Check Perfect Number (A perfect number is a positive integer that is equal to the
sum of its proper divisors, excluding itself. The number 28 is a perfect number.
• Its divisors (excluding itself):
→ 1, 2, 4, 7, 14
• Sum of those divisors:
→ 1 + 2 + 4 + 7 + 14 = 28
So, 28 is a perfect number.

Ans. num = int(input("Enter a number: "))


sum_divisors = 0
for i in range(1, num):
if num % i == 0:
sum_divisors += i
if sum_divisors == num:
print("The number is a Perfect number.")
else:
print("The number is not a Perfect number.")

6 # Check Palindrome: A palindrome number is a number that reads the same forwards
and backwards.
✅ Examples:
• 121 → reversed is 121 ✅
• 1331 → reversed is 1331 ✅
• 7 → reversed is 7 ✅

Ans. num = int(input("Enter a number: "))


n = num
reversed_num = 0
while n > 0:
digit = n % 10
reversed_num = reversed_num * 10 + digit
n //= 10
if reversed_num == num:
print("The number is a Palindrome.")
else:
print("The number is not a Palindrome.")

7 Write a program to input a number and check if the number is a prime or composite
number.

Ans. num = int(input("Enter a number: "))


# Check for edge cases first
if num <= 1:
print("The number is neither Prime nor Composite.")
else:
is_prime = True
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
is_prime = False
break
if is_prime:
print("The number is a Prime number.")
else:
print("The number is a Composite number.")

8 ● Display the terms of a Fibonacci series.


# Print N terms of Fibonacci series:
# Enter how many terms: 10
# 0 1 1 2 3 5 8 13 21 34

Ans. num = int(input("Enter how many terms :"))


first = 0
second = 1
print(first, end = ' ')
print(second, end = ' ')
for a in range(1, num-1):
third = first + second
print(third, end = ' ')
first , second = second , third
print()
#Method-2
n=int(input('Enter number of terms:'))
print(0,end=' ')
a=0
b=1
for i in range(n-1):
a,b=b+a,a
print(a,end=' ')
print()

9 ● Write a program to input two numbers and compute the Greatest Common
Divisor (GCD) and Least Common Multiple (LCM) of two integers.

Ans. # Input two numbers


a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
# Store original values for LCM calculation
x=a
y=b
# Compute GCD using Euclidean algorithm
while b != 0:
temp = b
b=a%b
a = temp

gcd = a
print("GCD is:", gcd)

# Compute LCM using the relation: LCM = (x * y) // GCD


lcm = (x * y) // gcd
print("LCM is:", lcm)

10 ● Write a Python program to input a string or sentence and Count and display
the number of vowels, consonants, uppercase, lowercase characters in string.
Input a string

Ans. text = input("Enter a string or sentence: ")


# Initialize counters
vowels = 0
consonants = 0
uppercase = 0
lowercase = 0
vowel_set = 'aeiouAEIOU'
for ch in text:
if ch.isalpha(): # Check if character is a letter
if ch in vowel_set:
vowels += 1
else:
consonants += 1
if ch.isupper():
uppercase += 1
elif ch.islower():
lowercase += 1
print("Number of vowels:", vowels)
print("Number of consonants:", consonants)
print("Number of uppercase letters:", uppercase)
print("Number of lowercase letters:", lowercase)

11 Write a program to input line(s) of text from the user until enter is pressed. Count the
total number of characters in the text (including white spaces), total number of
alphabets, total number of digits, total number of special symbols and total number of
words in the given text. (Assume that each word is separated by one space).

Ans. userInput = input("Write a sentence: ")


totalChar = len(userInput)
print("Total Characters: ",totalChar)
totalAlpha = totalDigit = totalSpecial = 0
for a in userInput:
if a.isalpha():
totalAlpha += 1
elif a.isdigit():
totalDigit += 1
else:
totalSpecial += 1
print("Total Alphabets: ",totalAlpha)
print("Total Digits: ",totalDigit)
print("Total Special Characters: ",totalSpecial)
words=len(userInput.split())
print("Number of words=",words)

12 Write a Python program to input coefficients a, b and c for a quadratic equation ax2 +
bx + c=0 and find and print the roots and nature of roots with appropriate messages.

D = b2 - 4ac
If D > 0 then roots are real and different.
Roots are:
root1 = (-b + √D) / (2 a)
root2 = (-b - √D) / (2 a)

If D=0 then roots are real and equal.


Roots are:
root1 = root2= -b / (2 a)

If D<0 then roots are imaginary or complex.

Ans. a = float(input("Enter coefficient a: "))


b = float(input("Enter coefficient b: "))
c = float(input("Enter coefficient c: "))

print("\nQuadratic Equation: ",a,'*x²+', b,'*x+',c)


D = b**2 - 4*a*c

print("Discriminant (D) = ", D)

if D > 0:
print("The equation has two distinct real roots.")
root1 = (-b + (D)**0.5) / (2 * a)
root2 = (-b - (D)**0.5) / (2 * a)
print("Root 1 =", root1)
print("Root 2 =", root2)
elif D == 0:
print("The equation has two equal real roots.")
root1 = -b / (2 * a)
root2 = -b / (2 * a)
print("Root 1 =", root1)
print("Root 2 =", root2)
else:
print("The equation has two complex roots.")

You might also like