0% found this document useful (0 votes)
5 views

Python Basics - ACT

Uploaded by

alvindale joyosa
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Python Basics - ACT

Uploaded by

alvindale joyosa
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

# Python Basics: Operators and Variables

## Introduction
In this exercise, you will practice using variables and basic operators in Python. Follow the instructions
and complete the code cells.
### Part 1: Variable Assignment
Assign values to variables `a` and `b`. Then, print their values.
```python
# Part 1: Variable Assignment
# Assign values to variables a and b
a = 10 # Change this value
b = 20 # Change this value
# Print the values of a and b
print("The value of a is:", a)
print("The value of b is:", b)
```
### Part 2: Basic Arithmetic
Assign values to variables `x` and `y`. Perform addition, subtraction, multiplication, and division. Print the
results.
```python
# Part 2: Basic Arithmetic
# Assign values to variables x and y
x = 15 # Change this value
y = 5 # Change this value
# Perform arithmetic operations
addition = x + y
subtraction = x - y
multiplication = x * y
division = x / y
# Print the results
print("Addition:", addition)
print("Subtraction:", subtraction)
print("Multiplication:", multiplication)
print("Division:", division)
```

### Part 3: Comparison Operations


Assign values to variables `m` and `n`. Perform and print the results of comparison operations.

```python
# Part 3: Comparison Operations
# Assign values to variables m and n
m = 8 # Change this value
n = 12 # Change this value
# Perform comparison operations
print("m equals n:", m == n)
print("m not equals n:", m != n)
print("m greater than n:", m > n)
print("m less than n:", m < n)
print("m greater than or equals n:", m >= n)
print("m less than or equals n:", m <= n)
```

### Part 4: Logical Operations


Assign boolean values to variables `p` and `q`. Perform and print the results of logical operations.

```python
# Part 4: Logical Operations
# Assign boolean values to variables p and q

p = True # Change this value


q = False # Change this value

# Perform logical operations


print("p and q:", p and q)
print("p or q:", p or q)
print("not p:", not p)
```

### Part 5: Combined Operations

Combine arithmetic and comparison operations. Assign values to variables `r` and `s`. Perform a
combined operation and print the result.

```python
# Part 5: Combined Operations
# Assign values to variables r and s

r = 7 # Change this value


s = 3 # Change this value

# Perform a combined operation


combined_result = (r + s) * (r - s) > r

# Print the result


print("Combined operation result:", combined_result)
```

You might also like