Skip to content

Python 501 訊息顯示

Python TQC

題目說明:

請撰寫一程式,呼叫函式compute(),該函式功能為讓使用者輸入系別(Department)、學號(Student ID)和姓名(Name)並顯示這些訊息。

範例輸入
Information Management
123456789
Tina Chen

範例輸出

Department: Information Management
Student ID: 123456789
Name: Tina Chen

題目解析

1. 問題分析

這個問題要求我們撰寫一個 Python 程式,呼叫函式 compute() 來顯示使用者輸入的系別、學號和姓名。

2. 解題思路

我們可以使用以下步驟來解決這個問題:

  1. 定義一個函式 compute()
  2. 在函式 compute() 中,使用 input() 函數輸入使用者輸入的系別、學號和姓名。
  3. 使用 print() 函數輸出使用者輸入的系別、學號和姓名。
  4. 在主程式中,呼叫函式 compute()

3. 思考方向

在解決這個問題時,我們可以思考以下幾個問題:

  • 如何定義一個函式?
  • 如何使用 input() 函數輸入使用者輸入?
  • 如何使用 print() 函數輸出資料?

Solution

1
2
3
4
5
6
7
8
9
def compute():
  a = input()
  b = input()
  c = input()
  print('Department: %s'%a)
  print('Student ID: %s'%b)
  print('Name: %s'%c)

compute()

Last update : 13 novembre 2024
Created : 13 novembre 2024

Comments

Comments