HW03 判斷敘述式
1.NotebookLM
1. 專案名稱
college-cricket-eligibility
2. Python 程式碼(main.py)
# College Cricket Eligibility# Input the player's ageage = int(input('Enter the age:'))# Check whether the age is between 15 and 18if not (age < 15) and not (age > 18): print('You are Eligible to play in College Cricket:')else: print('Sorry You cant play')3. 程式說明
age = int(input(...)):讓使用者輸入年齡,並轉換成整數。age < 15:判斷年齡是否小於 15 歲。age > 18:判斷年齡是否大於 18 歲。not:將判斷結果反轉。and:要求兩個條件都成立,才會進入符合資格的情況。print():顯示是否符合參加大學板球活動的年齡資格。
判斷規則: 年齡介於 15~18 歲(包含 15 歲與 18 歲)即可參加。
4. 執行結果
Case 1:輸入 24 歲
Enter the age:24 Sorry You cant play
Case 2:輸入 16 歲
Enter the age:16 You are Eligible to play in College Cricket:
5. GitHub README.md
將以下內容複製到 GitHub 專案中的 README.md 檔案。
College Cricket Eligibility
Introduction
This is a simple Python program that checks whether a player is eligible to play college cricket based on their age.
The player is eligible if their age is between 15 and 18, inclusive.
Program Code
age = int(input('Enter the age:'))
if not (age < 15) and not (age > 18):
print('You are Eligible to play in College Cricket:')
else:
print('Sorry You cant play')How It Works
The program asks the user to enter their age.
The
int()function converts the input into an integer.The
ifstatement checks whether the age is between 15 and 18.If the condition is true, the program displays an eligibility message.
Otherwise, the program displays a message indicating that the player is not eligible.
Example Output
Case 1
Enter the age:24
Sorry You cant playCase 2
Enter the age:16
You are Eligible to play in College Cricket:Project Structure
college-cricket-eligibility/
│
├── main.py
└── README.mdRequirements
Python 3.x
How to Run
Install Python 3 if it is not already installed.
Download or clone this repository.
Open a terminal in the project folder.
Run the following command:
python main.pyEnter your age when prompted.
Concepts Used
Variables
User input
Integer conversion
if-elsestatementsComparison operators
Logical operators (
notandand)
Purpose
This project is designed for beginners who are learning Python programming and conditional statements.
6. GitHub 專案檔案結構
college-cricket-eligibility/
main.py
README.md
這樣就完成一個基本的 Python GitHub 專案。你可以把 main.py 和 README.md 上傳至同一個 Repository,方便展示程式碼與學習成果。










留言
張貼留言