0% found this document useful (0 votes)
51 views2 pages

Cpe 401

This document contains programming exercises and explanations. The first exercise increments a variable called var from 3 to 4 by adding 1 to its value and printing the results. The second exercise calculates the hypotenuse of a right triangle with sides of length 3.0 and 4.0 using the Pythagorean theorem and prints the result of 5.0.
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)
51 views2 pages

Cpe 401

This document contains programming exercises and explanations. The first exercise increments a variable called var from 3 to 4 by adding 1 to its value and printing the results. The second exercise calculates the hypotenuse of a right triangle with sides of length 3.0 and 4.0 using the Pythagorean theorem and prints the result of 5.0.
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/ 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