Lab 05 Itp
Lab 05 Itp
Expression
Expression or equation is the combination of operator and operand.
Operator
A symbol or sign that used for a specific action on its operand(s). Different
programming languages consist of different operators.
Operand
Any variable/constant/expression on which an operator performs its operation.
Arithmetic Operators
i. “+” Addition
ii. “-”Subtraction
iii. “*” Multiplication
iv. “/” Float Division
v. “//” Integer Division
vi. “**” Exponent
vii. “% Remainder
Errors
Errors or mistakes in a program are often referred to as bugs. They are almost always
the fault of the programmer. The process of finding and eliminating errors is called
debugging. Errors can be classified into three major groups:
Syntax errors: Python will find these kinds of errors when it tries to parse your
program, and exit with an error message without running anything. Syntax errors
are mistakes in the use of the Python language, and are analogous to spelling or
grammar mistakes in a language like English: for example, the sentence Would
you some tea? does not make sense – it is missing a verb.
Runtime errors: If a program is syntactically correct – that is, free of syntax
errors – it will be run by the Python interpreter. However, the program may exit
unexpectedly during execution if it encounters a runtime error – a problem which
was not detected when the program was parsed, but is only revealed when a
particular line is executed. When a program comes to a halt because of a runtime
error, we say that it has crashed.
Logical errors: Logical errors are the most difficult to fix. They occur when the
program runs without crashing, but produces an incorrect result. The error is
caused by a mistake in the program’s logic. You won’t get an error message,
because no syntax or runtime error has occurred. You will have to find the
problem on your own by reviewing all the relevant parts of your code – although
some tools can flag suspicious code which looks like it could cause unexpected
behavior.
Directions: You are required to complete the following tasks during the lab.
Task 1: Sum of the First n Positive Integers
Write a program that reads a positive integer, n, from the user and then displays the
sum of all of the integers from 1 to n. The sum of the first n positive integers can be
computed using the formula:
sum =(n)(n + 1)/2
Task 2: Write a program to calculate acceleration using 3rd equation of motion?
Vf = int(input ("Enter the value of Vf ="))
Vi = int(input ("Enter the value of Vi ="))
S = int(input ("Enter the value of S ="))
A=0
��2−��2
# Calculate the value of A using the equation of motion � = 2�
on the following
line
A = _____________________________________
Result:
Enter Temperature in centigrade =45
*****************************************
Fahrenheit Temperature = 113.0
*****************************************
If you read the height in meters and the weight in kilograms then body mass index is
computed using this slightly simpler formula:
����ℎ�
BMI = ℎ���ℎ� ×ℎ���ℎ�