HW02 運算子表達式
1.NotebookLM
https://notebook.google.com/notebook/38bdd2a8-374e-457e-a72a-6c5175a61f1f
2.YouTube
3.學習卡
4.測驗
5.寫1個程式需附加說明 Create a README For Github
115103104 % 7 + 1 = 5
1. GitHub 專案名稱
python-car-speed-calculator
專案功能:輸入汽車行駛的距離(公尺)與時間(秒),計算汽車的平均速度(公尺/秒)。
2. Python 程式碼:main.py
# Python Car Speed Calculator
# Calculate the speed of a car in meters per second.
# Ask the user to enter the distance in meters
distance = int(input("Enter the distance in meters: "))
# Ask the user to enter the time in seconds
time = int(input("Enter time in seconds: "))
# Calculate the speed
speed = distance / time
# Display the result with two decimal places
print("Speed of vehicle is %.2f" % speed, "meter/second")程式碼說明
程式碼 | 功能 |
|---|---|
| 讓使用者從鍵盤輸入資料 |
| 將輸入的資料轉換成整數 |
| 儲存行駛距離,單位是公尺 |
| 儲存行駛時間,單位是秒 |
| 計算平均速度 |
| 將計算結果顯示到小數點後兩位 |
| 在終端機顯示計算結果 |
公式:
注意:時間不能輸入 0,否則程式會發生除以零的錯誤。
3. GitHub README.md
以下是可以直接複製到 GitHub 的 README 文件。
Python Car Speed Calculator
A simple Python program that calculates the average speed of a car in meters per second.
Project Description
This project asks the user to enter the distance traveled by a car in meters and the time taken in seconds. The program then calculates and displays the car's average speed.
Formula
Speed = Distance / Time
- Distance: measured in meters (m)
- Time: measured in seconds (s)
- Speed: measured in meters per second (m/s)
Requirements
- Python 3
How to Run
- Download or clone this repository.
- Open a terminal in the project folder.
Run the following command:
python main.py
Example Output
Enter the distance in meters: 1500
Enter time in seconds: 45
Speed of vehicle is 33.33 meter/secondCode Explanation
- Use
input()to receive the distance and time from the keyboard. - Use
int()to convert the input values into integers. - Calculate the speed by dividing the distance by the time.
- Use
print()to display the result. - Use
%.2fto display the speed to two decimal places.
Project Structure
python-car-speed-calculator/
│
├── main.py
└── README.mdLearning Objectives
- Practice Python keyboard input with
input(). - Learn how to convert input values using
int(). - Practice arithmetic operations and division.
- Learn how to format decimal output.
- Practice creating and documenting a GitHub repository.
Author
Python Beginner Project
4. GitHub 專案檔案結構
python-car-speed-calculator/
main.py
Python 主程式:計算汽車速度
README.md
英文專案說明、公式、執行方式與輸出範例
5. 執行結果驗證
輸入距離 1500 公尺、時間 45 秒:
因此程式輸出:
Enter the distance in meters: 1500
Enter time in seconds: 45
Speed of vehicle is 33.33 meter/second完成後,你的 GitHub Repository 就會是一個完整的 Python 入門練習專案。 你可以把 main.py 和 README.md 分別建立在同一個 Repository 裡,並將 README 當作專案首頁的說明文件。










留言
張貼留言