重點:變數、運算、print、基本資料型態
練習:用 AI 解釋每個語法元素
num1 = 10
num2 = 5
result = num1 + num2
print("加總結果:", result)
price = 100
discount = 0.2
final_price = price * (1 - discount)
print("折扣後價格:", final_price)
length = 5
width = 3
area = length * width
print("面積是:", area)
a = 7
b = 2
print("除法結果:", a / b)
name = "會安"
greeting = "你好," + name
print(greeting)
city = "台北"
weather = "晴天"
print(f"{city} 今天是 {weather}")
text = "Python"
print("字串長度:", len(text))
word = "Hello"
print(word.upper())
age = "25"
age_num = int(age)
print("你明年將會是", age_num + 1, "歲")
height = 170
height_str = str(height)
print("身高:" + height_str + " 公分")
flag = True
print("布林值轉整數:", int(flag))
value = 3.14
print("轉成字串:", str(value))
name = "會安"
score = 95
print(f"{name} 的分數是 {score} 分")
item = "蘋果"
price = 30
print("{} 的價格是 {} 元".format(item, price))
pi = 3.14159
print("圓周率約為 %.2f" % pi)
name = "會安"
age = 30
print(f"{name} 明年將是 {age + 1} 歲")
x = 8
y = 3
print("整除:", x // y)
num = 7
print("平方:", num ** 2)
a = 10
b = 3
print("餘數:", a % b)
total = 100
people = 4
print("平均分配:", total / people)
a = 5
b = 10
print("a 小於 b:", a < b)
is_raining = False
print("是否需要帶傘:", not is_raining)
x = 3
y = 3
print("x 等於 y:", x == y)
score = 80
passed = score >= 60
print("是否及格:", passed)
name = "會安"
age = 30
print(f"{name} 明年將是 {age + 1} 歲")
length = 10
width = 4
area = length * width
print("長方形面積:", area)
score = 92
print("分數等級:", "優" if score >= 90 else "普通")
price = 250
discount = 0.15
final = price * (1 - discount)
print("折扣後價格:", round(final, 2))