Cpe 401

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Sapungan, John Alvin B.

BS Sanitary Engineering - 1201


sr-code: 23-05385 CPE 401

Programming Exercise 1:
Implement the following codes and explain what happens in the output.

var = 3
print(var)
var = var + 1
print(var)

The line var = 3 assigns the integer value 3 to the variable var, followed by print(var)

which prints the value of var, which is 3. Then, var = var + 1 increments the value of var

by 1, making it 4 (3 + 1), and print(var) prints the updated value of var, which is 4.
a = 3.0
b = 4.0
c = (a ** 2 + b ** 2) ** 0.5
print("c =", c)

The code defines the lengths of two sides of a right triangle as a (3.0) and b (4.0). Then,

it calculates the length of the hypotenuse using the Pythagorean theorem, which states

that in a right triangle, the square of the hypotenuse (c) is equal to the sum of the

squares of the other two sides (a and b). The result, the length of the hypotenuse (c), is

printed as 5.0.

You might also like