Oding
Oding
Ansh - 11B
COMPUTER SCIENCE
RECORD
FILE
ACADEMIC YEAR : 2024-2025
Index
Title Of
S No. Page No. Remarks.
Program.
Menu
1. Driven Program – 1.
6.
Menu
2. Driven Program – 2.
7.
Menu
3. Driven Program – 3.
8.
Menu
4. Driven Program – 4.
9.
Program
5. for a Pyramid Pattern – 5.
10.
Menu
6. Driven Program – 6.
11.
Program
for reading a No. and 12.
7. printing in its corresponding
words – 7.
Program to
read a String and find the
8. following using operations –
13.
8.
Menu
9. Driven Program – 9.
14.
Menu Driven
Program to store the
10. numbers in a list and do the
15.
following operations – 10.
CERTIFICATE
Roll No:…………
Date :
Questions :
1. Write a menu driven program to do the following.
a. area and perimeter of a circle.
b. area and perimeter of a rectangle.
c. convert the temperature from Fahrenheit to Celsius and vice-versa.
d. Program to calculate the simple and compound interest.
6. Write menu driven a program to read an integer and do the following task. a. Print the
number of digits and the sum of digits of a number. Example: if N = 3748 Output: Number
of digits=4, Sum of digits=22
b. Check whether the number is Armstrong or not.
c. Check whether the number is Palindrome or not.
d. Check whether the number is a Perfect number or not.
7. Write program to read a number and print it into its corresponding words.
For example, if the number is 368
Output: three six eight.
Questions :
8. Write a program to read a string and find the following.
a. Number of Alphabets
b. Number of Uppercase and Lowercase letters
c. Number of Digits
d. Number of Vowels and Consonants
e. Number of Special Characters
f. Number of Spaces
10. Write a menu driven program to store the numbers in a list and do the following
operations (Do not use built-in functions, other than len() function)
a. Print the smallest and the largest number in the list
b. Reverse the list elements
c. Swap the first half elements with the second half of the list.
d. Swap the elements at the even location with the elements at the odd location.
e. Multiply the odd numbers by 3 and the even numbers by 6 in the list.
Question 1 :
Write a menu driven program to do the following.
a. area and perimeter of a circle.
b. area and perimeter of a rectangle.
c. convert the temperature from Fahrenheit to Celsius
and vice-versa.
d. Program to calculate the simple and compound interest.
while True:
print("Menu: \n 1.Circle \n 2.Rectangle \n 3.Temp \n 4.Interest \n 5.Exit")
c=input("Choice:")
if c=='1':
r=float(input("Radius:"))
print("Area:",3.14*r*r,"Perimeter:",2*3.14*r)
elif c=='2':
l,w=map(float,input("Length,Width:").split(","))
print("Area:",l*w,"Perimeter:",2*(l+w))
elif c=='3':
t,v=input("Type (F/C),Value:").split(",")
if t=='C': print((float(v)*9/5)+32)
else: print((float(v)-32)*5/9)
elif c=='4':
p,r,t=map(float,input("Principal,Rate,Time:").split(","))
print("SI:",p*r*t/100,"CI:",p*(1+r/100)**t-p)
elif c=='5':break
else:print("Invalid")
OUTPUT:
Question 2 :
Write a menu driven program to do the following.
a. check whether the given number is odd or even.
b. check whether the given number is prime or not.
c. to print the factorial of a given number.
d. to print the multiplication table of a number
while True:
print("Menu: \n 1.Odd/Even \n 2.Prime \n 3.Factorial \n 4.Multiplication
Table \n 5.Exit")
c = input("Choice:")
if c == '1':
n = int(input("Enter Number:"))
print("Even" if n % 2 == 0 else "Odd")
elif c == '2':
n = int(input("Enter Number:"))
print(n > 1 and all(n % i for i in range(2, int(n**0.5) + 1)))
elif c == '3':
n = int(input("Enter Number:"))
f=1
for i in range(1, n + 1): f *= i
print(f)
elif c == '4':
n = int(input("Number:"))
for i in range(1, 11): print(f"{n} x {i} = {n * i}")
elif c == '5':
break
else:
print("Invalid")
OUTPUT: Menu:
1. Odd/Even
Menu: Menu: Menu:
2. Prime
1. Odd/Even 1. Odd/Even 1. Odd/Even
3. Factorial
2. Prime 2. Prime 2. Prime
4. Multiplication Table
3. Factorial 3. Factorial 3. Factorial
5. Exit
4. Multiplication Table 4. Multiplication Table 4. Multiplication Table
Choice: 4
5. Exit 5. Exit 5. Exit
Number: 3
Choice: 1 Choice: 2 Choice: 3
3x1=3
Enter Number: 7 Enter Number: 11 Enter Number: 5
3x2=6
Odd True 120
3x3=9
Menu: 3 x 4 = 12
1. Odd/Even 3 x 5 = 15
2. Prime 3 x 6 = 18
3. Factorial 3 x 7 = 21
4. Multiplication Table 3 x 8 = 24
5. Exit 3 x 9 = 27
Choice: 5 3 x 10 = 30
Question 3 :
Write a menu driven program for the following.
a. To read the age of a person and check whether he/she is
eligible for voting.
b. to read the height and weight of a person and print the BMI
accordingly.
c. To calculate the HCF and LCM of two numbers
d. To find the largest among the three numbers.
while True:
print("\nMenu: \n 1.Vote \n 2.BMI \n 3.HCF/LCM \n 4.Largest \n 5.Exit")
c = input("Choice:")
if c == '1':
age = int(input("Age:"))
print("Eligible" if age >= 18 else "Not Eligible")
elif c == '2':
h, w = map(float, input("Height(m),Weight(kg):").split(","))
print("BMI:", w / (h ** 2))
elif c == '3':
a, b = map(int, input("Numbers:").split(","))
def hcf(a, b):
while b: a, b = b, a % b
return a
print("HCF:", hcf(a, b), "LCM:", (a * b) // hcf(a, b))
elif c == '4':
nums = list(map(int, input("Numbers:").split(",")))
print("Largest:", max(nums))
elif c == '5':
break
else:
print("Invalid")
OUTPUT:
Menu: Menu: Menu: Menu: Menu:
1.Vote 1.Vote 1.Vote 1.Vote 1.Vote
2.BMI 2.BMI 2.BMI 2.BMI 2.BMI
3.HCF/LCM 3.HCF/LCM 3.HCF/LCM 3.HCF/LCM 3.HCF/LCM
4.Largest 4.Largest 4.Largest 4.Largest 4.Largest
5.Exit 5.Exit 5.Exit 5.Exit 5.Exit
Choice: 1 Choice: 2 Choice: 3 Choice: 4 Choice: 5
Age: 20 Height(m),Weight(kg): 1.75,70 Numbers: 12,18 Numbers: 4,5,6,2,1
Eligible BMI: 22.86 HCF: 6 LCM: 36 Largest: 6
Question 4 :
Write a menu driven program for the following.
a. to print the sum of the first n natural numbers.
b. to print the sum of all the odd numbers upto ‘n’.
c. 1-X+X2 -X 3+X4……………………..Xn
d. X+X2 /2!-X 3 /3!+X4 /4!.................Xn /n!
import math
while True:
print("Menu: \n 1. Natural Sum \n 2. Odd Sum \n 3. Series1 \n 4. Series2 \n 5. Exit")
choice = input("Enter your choice (1-5): ")
if choice == '1':
n = int(input("Enter the value of n: "))
total = sum(range(1, n + 1))
print("Sum of the first", n, "natural numbers is:", total)
elif choice == '2':
n = int(input("Enter n: "))
total = sum(i for i in range(1, n + 1, 2))
print("Sum of all odd numbers up to", n, "is:", total)
elif choice == '3':
else:
x, n = map(int, input("Enter x, n: ").split(","))
sum_series = sum([((-1) ** (i % 2)) * (x ** (i + 1)) / math.factorial(i + 1)
for i in range(n)])
print("Sum of the series:", sum_series)
OUTPUT:
Menu: Menu: Menu:
1. Natural Sum 1. Natural Sum 1. Natural Sum
2. Odd Sum 2. Odd Sum 2. Odd Sum
3. Series1 3. Series1 3. Series1
4. Series2 4. Series2 4. Series2
5. Exit 5. Exit 5. Exit
Enter your choice (1-5): 1 Enter your choice (1-5): 2 Enter your choice (1-5): 3
Enter the value of n: 5 Enter n: 7 Enter x, n: 2, 3
Sum of the first 5 natural numbers is: 15 Sum of all odd numbers up to 7 is: 16 Sum of the series: -15.0
Menu:
1. Natural Sum
2. Odd Sum
3. Series1
4. Series2
5. Exit
Enter your choice (1-5): 4
Enter x, n: 1, 5
Sum of the series: 0.7166666666666667
Question 5 :
Write a program to print the following pyramids.
# Pyramid (i)
for i in range(1, 6):
print("* " * i)
# Pyramid (ii)
for i in range(5, 0, -1):
for j in range(1, i+1):
print(j, end=" ")
print()
# Pyramid (iii)
for i in range(1, 6):
for j in range(1, i + 1):
print(chr(64 + j), end=" ")
print()
OUTPUT:
Question 6 :
Write menu driven a program to read an integer and do the
following task. a. Print the number of digits and the sum of
digits of a number. Example: if N = 3748 Output: Number of
digits=4, Sum of digits=22
b. Check whether the number is Armstrong or not.
c. Check whether the number is Palindrome or not.
d. Check whether the number is a Perfect number or not.
while True:
print("Menu: \n1. Digits & Sum\n2. Armstrong\n3. Palindrome\n4. Perfect\n5. Exit")
choice = int(input("Enter choice (1-5): "))
if choice == 5: break
if choice == 1:
digits = len(str(num))
digit_sum = sum(int(digit) for digit in str(num))
print(f"Digits = {digits}, Sum = {digit_sum}")
elif choice == 2:
n = len(str(num))
if sum(int(digit) ** n for digit in str(num)) == num:
print(f"{num} is an Armstrong number.")
else:
print(f"{num} is not an Armstrong number.")
elif choice == 3:
if str(num) == str(num)[::-1]:
print(f"{num} is a Palindrome.")
else:
print(f"{num} is not a Palindrome.")
elif choice == 4:
if sum(i for i in range(1, num) if num % i == 0) == num:
print(f"{num} is a Perfect number.")
else:
print(f"{num} is not a Perfect number.")
else:
print("Invalid choice!")
Question 7 :
Write program to read a number and print it into its
corresponding words.
For example, if the number is 368
Output: three six eight.
OUTPUT:
Enter number: 789
seven eight nine
print("Alphabets:", a)
print("Uppercase:", u)
print("Lowercase:", l)
print("Digits:", d)
print("Vowels:", v)
print("Consonants:", c)
print("Special Characters:", sp)
print("Spaces:", s)
OUTPUT:
Enter a string: Hello World 2024!
Alphabets: 10
Uppercase: 2
Lowercase: 8
Digits: 4
Vowels: 3
Consonants: 7
Special Characters: 1
Spaces: 2
Question 9 :
Write a menu driven program to perform the following
operation.
a. read a string and print its reverse. (without using slicing
like [::-1]).
b. Check whether the string is palindrome or not
c. read a sentence and print each word one by one.
d. read a sentence and print the words that contain the
letter ‘A’
while True:
print("\nMenu:")
print("a. Reverse a string")
print("b. Check for palindrome")
print("c. Print words in a sentence")
print("d. Print words with 'A'")
print("e. Exit")
if choice == 'a':
string = input("Enter a string: ")
reversed_string = ''
for i in range(len(string) - 1, -1, -1):
reversed_string += string[i]
print("Reversed string:", reversed_string)
elif choice == 'b':
string = input("Enter a string: ")
if string == string[::-1]: # Using slicing for palindrome check
print("The string is a palindrome.")
else:
print("The string is not a palindrome.")
elif choice == 'c':
sentence = input("Enter a sentence: ")
words = sentence.split()
for word in words:
print(word)
elif choice == 'd':
sentence = input("Enter a sentence: ")
words = sentence.split()
for word in words:
if 'A' in word:
print(word)
elif choice == 'e':
break
else:
print("Invalid choice. Please try again.")
Question 10 :
Write a menu driven program to perform the following
operation.
a. read a string and print its reverse. (without using slicing
like [::-1]).
b. Check whether the string is palindrome or not
c. read a sentence and print each word one by one.
d. read a sentence and print the words that contain the
letter ‘A’
while True:
print("\nMenu:")
print("1. Print smallest and largest number")
print("2. Reverse the list")
print("3. Swap the first half with the second half")
print("4. Swap elements at even locations with odd locations")
print("5. Multiply odd numbers by 3 and even numbers by 6")
print("6. Exit")
if choice == 1:
if len(numbers) == 0:
print("The list is empty.")
else:
smallest = largest = numbers[0]
for number in numbers:
if number < smallest:
smallest = number
if number > largest:
largest = number
print("Smallest number:", smallest)
print("Largest number:", largest)
elif choice == 2:
start, end = 0, len(numbers) - 1
while start < end:
numbers[start], numbers[end] = numbers[end], numbers[start]
start += 1
end -= 1
print("Reversed list:", numbers)
elif choice == 3:
mid = len(numbers) // 2
if len(numbers) % 2 == 0:
numbers[0:mid], numbers[mid:] = numbers[mid:], numbers[0:mid]
else:
numbers[0:mid + 1], numbers[mid + 1:] = numbers[mid + 1:], numbers[0:mid + 1]
print("List after swapping halves:", numbers)
elif choice == 4:
for i in range(1, len(numbers), 2):
if i < len(numbers):
numbers[i - 1], numbers[i] = numbers[i], numbers[i - 1]
print("List after swapping even and odd indexed elements:", numbers)
elif choice == 5:
for i in range(len(numbers)):
if numbers[i] % 2 == 0:
numbers[i] *= 6
else:
numbers[i] *= 3
print("List after multiplying:", numbers)
elif choice == 6:
print("Exiting the program.")
break
else:
print("Invalid choice. Please try again.")