Yadav Saar GR 11 Cs Codes
Yadav Saar GR 11 Cs Codes
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.
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.
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 ✅
7 Write a program to input a number and check if the number is a prime or composite
number.
9 ● Write a program to input two numbers and compute the Greatest Common
Divisor (GCD) and Least Common Multiple (LCM) of two integers.
gcd = a
print("GCD is:", gcd)
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
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).
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:
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.")