0% found this document useful (0 votes)
7 views3 pages

Lab 05 Itp

Uploaded by

acesenpai191
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Lab 05 Itp

Uploaded by

acesenpai191
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Lab 5: Expressions and Programing Errors

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 = _____________________________________

# Complete the following print commands to get specified output/result.


print ____________________________________
print_____________________________________
print _____________________________________

Your result should be as following:


Enter the value of Vf =22
Enter the value of Vi =12
Enter the value of S =32
************------------------*************
The resultant acceleration = 5.3125
*************----------------*************

Task 3: Write a Python program to convert a temperature given in degrees Celsius to


its equivalent in degrees Fahrenheit. You can assume that F = 9/5 x (C + 32), where C
is the temperature in °C and F is the temperature in °F. Your program should ask the
user for an input value, and print the output. The input and output values should be
floating-point numbers.

C = int(input("Enter Temperature in centigrade ="))


# Calculate the value of F using the formula F = 9/5 x (C + 32)on the following line
F=
print("*****************************************");
print("Fahrenheit Temperature =", F);
print("*****************************************");

Result:
Enter Temperature in centigrade =45
*****************************************
Fahrenheit Temperature = 113.0
*****************************************

Task 4: Body Mass Index


Write a program that computes the body mass index (BMI) of an individual. Your
program should begin by reading a height and weight from the user. Then it should
use one of the following two formulas to compute the BMI before displaying it. If you
read the height in inches and the weight in pounds then body mass index is computed
using the following formula:
����ℎ�
BMI = ℎ���ℎ� ×ℎ���ℎ� × 703

If you read the height in meters and the weight in kilograms then body mass index is
computed using this slightly simpler formula:
����ℎ�
BMI = ℎ���ℎ� ×ℎ���ℎ�

You might also like