新增一程式碼框,並輸入簡單程式碼後,按執行。
1. print("ABC")
輸出一個字串 ABC
2. print(5 * 4 + 3)
運算一條數學題
3. x = 3
print(x * 4)
設定一個變數 x 的值為 3
輸出變數 x 及運算後結果
4. print("The number is ", x, ".")
同時輸出字串及變數 (以 , 分隔)
5. print("Apple" * 3)
把一個字串 * 3,即重覆字串三次
6. x = input("Please enter a string: ")
要求輸入一個字串,並儲存在變數 x
7. y = int(input("Please enter a number: "))
要求輸入一個整數,並儲存在變數 y
試根據下列輸出的結果,寫出相應的程式碼。(2分)
Please input an integer [ 3 ]
Please input a string [ ICT ]
輸出 : ICTICTICT
(1分)
Please input an integer [ 5 ]
輸出: 5, 10, 15, 20, 25, 30, 35, 40 [ 列出 8 個 5 的倍數]
8. import random
print(random.random())
print(random.randint(5, 9))
滙入程式集
輸出一個介乎 0 至 1 的小數
輸出一個介乎 5 至 9 的整數
(2分)
Input min [ 7 ]
Input max [ 14 ]
結果: Random number between 7 and 14 is 12 [產生一個由 7 至 14 的隨機整數]