Page 466 - ComputerScience_Class_11
P. 466
D. Higher Order Thinking Skills (HOTS)
1. A loan interest calculation system calculates interest based on the principal amount, rate of interest and time in years.
The system uses the following formula:
Here is the code:
principal = 10000
rate = 5
time = 5
compound_interest = principal * (1 + rate / 100) * time
print("The compound interest is:", compound_interest)
However, the result is incorrect. The program calculates the total amount with compound interest instead of just the interest.
The output is 52500.0, but the expected output for interest is 2762.81. What is the logical error?
2. Analyse a scenario where a NameError could cause the failure of a program that assigns values to user input fields. What
precautions should be taken to ensure that all variables are defined before use?
E. Case study based questions.
1. You are writing a Python program to calculate the average marks of a student based on their scores in five subjects. The code runs
without any errors and displays a result, but it’s giving an incorrect average. After checking, you realise that the program is adding
the marks of the first four subjects but dividing the sum by five, leading to an incorrect result.
subject1 = 80
subject2 = 75
subject3 = 90
subject4 = 85
subject5 = 70
total_marks = subject1 + subject2 + subject3 + subject4
average = total_marks / 5
print("Average Marks:", average)
The issue lies in the line where the program calculates the total marks. The fifth subject (subject5) is missing in the addition of
marks, but it is still used to divide the total. This leads to a logical error in the calculation of the average.
Based on the given case, answer the following questions:
a. What is the logical error in the program?
b. Why is the program running without any errors but still producing incorrect results?
c. How would you correct the logical error?
F. Write the python program for the following:
1. Write the program to find the length of a string.
2. Write the program to find the sum of digits in a number.
3. Write the program to display the common elements between two lists.
G. Find the output of the following programs.
1. school = input("Enter your school name: ")
print(f"My school name is {school}")
2. a = int(input("Enter first value: "))
b = int(input("Enter second value: "))
print("Values", a, b, sep=" | ")
3. num1 = 85
num2 = 90
print(f"The sum of {num1} and {num2} is {num1 + num2}.")
464 Touchpad Computer Science (Ver. 3.0)-XI

