SEESathi
HomeSubjectsPast PapersMock TestSavedSearch
SEESathi

Empowering every Class 10 student across Nepal with world-class, beautifully structured study notes and solved questions.

Study

  • Master Notes
  • Question Bank
  • Past Papers

Subjects

  • Science & Technology
  • English
  • नेपाली
  • Social Studies
  • Computer Science
  • Mathematics

Resources

  • SEE Grading Guide
  • Syllabus Breakdown
  • Topper Answer Sets
  • Mock Test Simulator

Legal

  • About Mission
  • Editorial Board
  • Privacy Policy
  • Terms of Use

© 2026 SEE Sathi Technologies Pvt. Ltd. Kathmandu, Nepal.

Built for every Class 10 student across Nepal

Python — Error HandlingSolved Questions· Unit 4
Computer Science · Chapter 04d
17 solved questions

Programming In Python - 4.4 Error Handling

Every question in this chapter, answered and explained — step-by-step solutions drawn live from the chapter library across 2 question sections.

Concept in Practice 5 — Error Handling7Textbook-Based Content: Lab Activity Programming Exercises10
01

Concept in Practice 5 — Error Handling

7
1Textbookcs3-q1

Which Python keyword is used to handle exceptions (errors) in a program?

Ans.b) except
2Textbookcs3-q2

What will this code output if the user enters a non-numeric value like abc? try: num = int(input("Enter a number: ")); print("You entered:", num); except ValueError: print("Invalid input")

Ans.c) Invalid input
3Textbookcs3-q3

What type of error is caught by the following block? try: x = 5 / 0; except ZeroDivisionError: print("Cannot divide by zero!")

Ans.b) ZeroDivisionError
4Textbookcs3-q4

What is the purpose of the else block in a try-except-else statement?

Ans.b) Runs only if no exception occurs
5Textbookcs3-q5

Which of the following can be used to handle multiple exceptions in Python?

Ans.a) Multiple except blocks
6Textbookcs3-q6

What does the finally block do?

Ans.c) Always executes, whether error occurs or not
7Textbookcs3-q7

Which of the following statements about error handling in Python is TRUE?

Ans.c) The except block handles the error if any error occurs in the try block.
02

Textbook-Based Content: Lab Activity Programming Exercises

10
1Textbookcs7-q1

Find the square root of 144 using the math library.

Ans.import math result = math.sqrt(144) print("Square root of 144 is:", result) # Output: # Square root of 144 is: 12.0
2Textbookcs7-q2

Write a program to find the value of 5 raised to the power of 3 using the math library.

Ans.import math result = math.pow(5, 3) print("5 to the power of 3 is", result) # Output: # 5 to the power of 3 is 125.0
3Textbookcs7-q3

Draw a straight horizontal line of 150 units using turtle.

Ans.import turtle t = turtle.Turtle() t.forward(150) turtle.done()
4Textbookcs7-q4

Use turtle to draw a square of side 100 units.

Ans.import turtle t = turtle.Turtle() for i in range(4): t.forward(100) t.left(90) turtle.done()
5Textbookcs7-q5

Write a Python program to read two numbers from the user and subtract them. Handle invalid input errors.

Ans.try: a = int(input("Enter first number: ")) b = int(input("Enter second number: ")) result = a - b print("Difference:", result) except ValueError: print("Invalid input! Please enter numbers only.")
6Textbookcs7-q6

Write a Python program to enter your favorite color. If the input is blank, display 'Favorite color is required!' using a try-except block.

Ans.try: color = input("Enter your favorite color: ") if color == "": raise ValueError("Favorite color is required!") print("Your favorite color is:", color) except ValueError as e: print(e)
7Textbookcs7-q7

Write a program to create a file named message.txt and write your name and a welcome message into it. Then display the message by reading the file.

Ans.file = open("message.txt", "w") file.write("Name: Ramesh\nWelcome to Python programming!") file.close() file = open("message.txt", "r") content = file.read() print(content) file.close()
8Textbookcs7-q8

Write names and ages of 3 friends into a CSV file named friends.csv, then read and display all the records.

Ans.import csv file = open("friends.csv", "w", newline="") writer = csv.writer(file) writer.writerow(["Name", "Age"]) for i in range(3): name = input("Enter friend's name: ") age = input("Enter friend's age: ") writer.writerow([name, age]) file.close() file = open("friends.csv", "r") reader = csv.reader(file) for row in reader: print(row) file.close()
9Textbookcs7-q9

Create a CSV file named products.csv using the Pandas library containing the names, prices, and quantities of 3 products. Display a message after successfully saving the file.

Ans.import pandas as pd data = { "Product": ["Pen", "Notebook", "Eraser"], "Price": [20, 50, 10], "Quantity": [100, 60, 150] } products = pd.DataFrame(data) products.to_csv("products.csv", index=False) print("products.csv file has been created successfully.")
10Textbookcs7-q10

Create a vertical bar chart showing the number of students in five classes (Class 1 to Class 5) with different colors for each bar, width=0.4, and a legend.

Ans.import matplotlib.pyplot as plt classes = ['Class 1', 'Class 2', 'Class 3', 'Class 4', 'Class 5'] students = [] for c in classes: n = int(input(f"Enter number of students in {c}: ")) students.append(n) colors = ['red', 'green', 'blue', 'orange', 'purple'] plt.bar(classes, students, color=colors, width=0.4, label='Students') plt.title("Number of Students in Each Class") plt.xlabel("Class") plt.ylabel("Number of Students") plt.legend() plt.show()
Review the NotesBack to Chapter