Lab Session 3 - Python Operators (1) exercise
Lab Session 3 - Python Operators (1) exercise
2. Assumes the variables w, x, y and z are all integers, and that w=5, x=4, y=8 and z=2. What value will
be stored in result after each of the following statements execute?
1. x += y
2. z *= 2
3. y /= z
4. w %= z
3. What happens when Python evaluates the statement x += x - x when x has the value 3?
Answer:
1. x += 1
2. x /= 2
3. x -= 1
4. x += y
5. x -= (y + 7)
6. x* = 2
7. number_of_closed_cases = number_of_closed_cases + 2*ncc
5. Write a Python program to solve (x + y) * (x + y) / 2*x.
Test Data: x = 4, y = 3
6. Read two integers from the user and print three lines where:
1. The first line contains the sum of the two numbers.
2. The second line contains the difference of the two numbers (first - second).
3. The third line contains the product of the two numbers.
9. Write a Python program to add two positive integers without using the '+' operator.
Note: Use bit wise operations to add two numbers.
10. Consider the following program that attempts to compute the circumference of a circle given the
radius entered by the user. Given a circle’s radius, r, the circle’s circumference, C is given by the
formula: C = 2pr
Program:
r=0
PI = 3.14159
# Formula for the area of a circle given its radius
C = 2*PI*r
# Get the radius from the user
r = float(input("Please enter the circle's radius: "))
# Print the circumference
print("Circumference is", C)
1. The program does not produce the intended result. Why?