AI Lab 1 17102024 121720pm
AI Lab 1 17102024 121720pm
BSCS 6-A
Total Marks 10
Objective(s):
To Understand about:
Task 1: Explore Python indentation, debug errors, and understand how indentation affects program behavior.
Task 2: Create an advanced calculator with extended mathematical functionalities and robust error handling.
Task 3: Implement a comprehensive unit conversion calculator with support for advanced conversions and user-
defined rates.
Lab Tasks:
Objective: To explore the importance of proper indentation in Python and understand how to debug common
indentation errors.
Question:
1. Open IDLE and write the following program to calculate the sum of two numbers.
python
Copy code
def add_numbers(a, b):
print("The sum is:", a + b)
add_numbers(10, 20)
oExperiment with different indentations for the print and add_numbers lines.
oMake a note of errors that occur due to incorrect indentation and correct them.
oModify the program to include another function for subtraction and observe how indentation
affects nested functions.
2. Extend the program to:
o Handle errors for incorrect inputs (e.g., entering strings instead of numbers).
o Add a try-except block to catch and display error messages.
Solution [copy your code solution and output below, adjust the font accordingly]
Objective: To create a fully functional calculator with advanced operations and robust error handling.
Question:
Solution [copy your code solution and output below, adjust the font accordingly]
Task 3: Advanced Unit Conversion Calculator
Objective: To develop a versatile unit conversion calculator with support for advanced conversions and robust
error handling.
Question:
1. Write a Python program to implement a unit conversion calculator with the following features:
o A Menu function to display options:
Meter to kilometer
Kilometer to meter
Centimeter to meter
Centimeter to millimeter
Additional options:
Fahrenheit to Celsius
Celsius to Fahrenheit
Pounds to kilograms
Kilograms to pounds
o Separate functions for each conversion.
2. Additional Tasks:
o Include a feature to allow users to input custom conversion rates for units not listed in the menu.
o Implement error handling for invalid input values (e.g., negative distances or temperatures outside
a realistic range).
3. The program should loop continuously, allowing multiple conversions until the user chooses to quit.
Solution [copy your code solution and output below, adjust the font accordingly]
Submission Instructions: Submit your Python code and explanations. Ensure to provide screenshots of all
visualizations along with your answers.