AU Fundamentals of Python Programming¶
Ex4-1(練習4-1):練習格式化輸出¶
自由印太聯盟由美國,日本,澳洲和印度組成
The Free Indo-Pacific Alliance is composed of the United States, Japan, Australia and India
Step 1: 宣告四個國家的變數¶
n0=""; n1= ""; n2=""; n3="" #<-?
Step 2: 使用f-string 印出¶
print(f"自由印太聯盟由, , 和 組成") #<-?
自由印太聯盟由, , 和 組成
Ex4-2(練習4-2):簡單計算機¶
輸入三個數字a,b,c計算其和及積
Enter three numbers a, b, c to calculate the sum and product
Step 1: 宣告三個數字 a,b,c¶
a = .0; b=.0; c=.0; sum = .0; product = .0
print(f"numbers={a}, {b}, {c}, sum = {sum}, product = {product}")
numbers=0.0, 0.0, 0.0, sum = 0.0, product = 0.0
Step 2: 輸入三個數字 a,b,c
a = float(input("a:"))
b = #<-?
c = #<-?
print(f"numbers={a}, {b}, {c}")
File "/tmp/ipykernel_799/1077063896.py", line 2
b = #<-?
^
SyntaxError: invalid syntax
Step 3: 計算三個數字 a,b,c的和¶
sum = #<-?
print(f"numbers={a}, {b}, {c}, sum = {sum}")
Step 4: 計算三個數字 a,b,c的積¶
product = #<-?
print(f"numbers={a}, {b}, {c}, product = {product }")