Assignment #01
Assignment #01
CS1A-043
Assignment # 01
Q1. Discuss how programming errors can be classified into three distinct
types: syntax errors, runtime …… errors, and logic errors, and explain the
key characteristics of each. Provide a Python code snippet …… that
demonstrates each of these error types.
Syntax Errors:
The error which is in the construction of codes written and
when the code does not follow the structure of the programming language.They
are detected by the compiler or interpreter at. the code compilation or
interpretation.
if x=5
print('x =',x)
Logic Errors:
Logic errors, occur when the code's logic is incorrect, which
leads to disruptive program behavior. The code may run without error messages,
but it won’t produce the expected output.These types of errors are the most
difficult to identify and correct because they involve incorrect program design or
algorithm.
radius = 3
area = 3.14 * radius * radius
print("Area of the circle:", area)
Like using this code the area calculated of the circle would be
wrong because the radius r is not multiplied by itself rather than it has power
exponent 2 like this r2 so the error is in the logic the formula is wrong and the
output would be wrong in this way.
1
Runtime Errors:
Runtime errors happen during the execution of the
program.These errors are not caught by the compiler or interpreter and may
cause the program to fully terminate.The most common runtime error is
division by zero.
x=5
y=0
result = x / y
When this code will be executed it will give an error saying Zero Division Error:
during the execution and it will not be executed.
Q2. Rewrite the following Python code to convert it into the preferred
format for handling multiple ……alternatives.
Kg_per_lbs = 0.45359237
meters_per_inch = 0.0254
# Compute BodyMassIndex
# Display result
2
Q3. Identify and list some common built-in Python functions that are
frequently used within for loop.scenarios for data processing and
manipulation.
These are some commonly used functions which are used in for loop
scenarios:
Continue: a function used during the loop to skip the remaining code during
current iteration only.
sum( ): sum function Calculates the sum of all the elements in an iterable,
such as a list of numbers.
min( ) and max( ): is used Find the minimum and maximum values in an
iterable, respectively.
any( ) and all( ): Check if any or all elements in an iterable satisfy a given
condition, respectively..