grade1 = 90

grade2 = 75

averageGrade = (grade1 + grade2) / 2

print("The average grade is", averageGrade)

The average grade is 82.5

Part 2: Arithmetic Expressions

Calculate the following in Python using variables and arithmetic operators:

  1. num1 ← 10
  2. num2 ← 5
  3. num3 ← num1 + num2 * 2
  4. num4 ← (num1 + num2) * 2
  5. num5 ← num3 / 3 + num4
  6. Display the values of num3, num4, and num5.

Hint: Use +, -, *, /, and parentheses to control order of operations.

num1 = 10
num2 = 5

num3 = num1 + num2 * 2

num4 = (num1 + num2) * 2

num5 = num3 / 3 + num4

print("The value of num3 is", num3)
print("The value of num4 is", num4)
print("The value of num5 is", num5)

The value of num3 is 20
The value of num4 is 30
The value of num5 is 36.666666666666664

Part 3: Step-by-Step Algorithm Practice

Write Python code for this algorithm without using loops or if statements:

Algorithm:

  1. Set item to 7
  2. Create three variables: num1 = 3, num2 = 7, num3 = 9
  3. Check each variable manually to see if it equals item (just write it as a sequence of assignments and displays)
  4. Display "Item found" if a variable matches item
  5. At the end, display "Item not found" if none match

Hint: Since you haven’t learned if statements, just write a sequence that shows the comparisons step by step with comments.

item = 7

num1 = 3
num2 = 7
num3 = 9

print("Checking num1:", num1 == item)   
print("Checking num2:", num2 == item)  
print("Checking num3:", num3 == item)  

print("Item found" * (num1 == item))
print("Item found" * (num2 == item))
print("Item found" * (num3 == item))

any_found = (num1 == item) or (num2 == item) or (num3 == item)
print("Item not found" * (not any_found))

Checking num1: False
Checking num2: True
Checking num3: False

Item found

Part 4: Mixed Expressions

Write a Python program that:

  1. Create three variables: a = 8, b = 4, c = 10
  2. Calculate:
    • result1 = a + b * c
    • result2 = (a + b) * c
    • result3 = a + (b / c)
  3. Display all three results.

This will help you practice order of operations and arithmetic in Python.

a = 8
b = 4
c = 10

result1 = a + b * c
result2 = (a + b) * c
result3 = a + (b / c)

print("Result 1:", result1)
print("Result 2:", result2)
print("Result 3:", result3)

Result 1: 48
Result 2: 120
Result 3: 8.4