# Tactiverge Academy — companion code for "Values, variables and expressions"
# Lesson: https://tactiverge.win/academy/computational-engineering/python-fundamentals/values-variables-expressions/
# Licence: MIT (see https://tactiverge.win/open-engineering/). Examples appear in lesson order.

# ── Example 1 ────────────────────────────────────────
print("Hello, engineer!")


# ── Example 2 ────────────────────────────────────────
voltage = 9.0       # volts
resistance = 450.0  # ohms
current = voltage / resistance
print(current)


# ── Example 3 ────────────────────────────────────────
print(7 / 2)    # division: 3.5
print(7 // 2)   # floor division (whole part): 3
print(7 % 2)    # remainder: 1
print(2 ** 10)  # power: 1024


# ── Example 4 ────────────────────────────────────────
print(0.1 + 0.2)


# ── Example 5 ────────────────────────────────────────
import math
print(math.isclose(0.1 + 0.2, 0.3))   # True


# ── Example 6 ────────────────────────────────────────
current = 9.0 / 450.0
print(f"Current: {current * 1000:.1f} mA")


# ── Example 7 ────────────────────────────────────────
name = "servo"
print(name.upper())     # SERVO
print(len(name))        # 5
print(name + "-01")     # servo-01


# ── Example 8 ────────────────────────────────────────
readings = [20.2, 20.4, 19.8, 20.0]   # temperatures in °C
average = sum(readings) / len(readings)
print(f"Average: {average:.2f} °C")   # Average: 20.10 °C

print(readings[0])    # first item: 20.2
print(readings[-1])   # last item: 20.0
print(max(readings))  # 20.4
readings.append(20.6) # add a new reading at the end
print(len(readings))  # 5


# ── Example 9 ────────────────────────────────────────
import math

print(math.sqrt(2))                    # 1.4142135623730951
print(math.pi)                         # 3.141592653589793
print(math.cos(math.radians(60)))      # 0.5000000000000001


# ── Example 10 ────────────────────────────────────────
import math

length_cm = 10.0
angle_deg = 30.0
angle = math.radians(angle_deg)

x = length_cm * math.cos(angle)
y = length_cm * math.sin(angle)
print(f"Tip at ({x:.2f}, {y:.2f}) cm")
