HW03 判斷敘述式

 1.NotebookLM

2.YouTube





5.寫1個程式需附加說明 Create a README For Github
115103104 % 5 + 1 = 5

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. 程式說明

  1. age = int(input(...)):讓使用者輸入年齡,並轉換成整數。

  2. age < 15:判斷年齡是否小於 15 歲。

  3. age > 18:判斷年齡是否大於 18 歲。

  4. not:將判斷結果反轉。

  5. and:要求兩個條件都成立,才會進入符合資格的情況。

  6. 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

  1. The program asks the user to enter their age.

  2. The int() function converts the input into an integer.

  3. The if statement checks whether the age is between 15 and 18.

  4. If the condition is true, the program displays an eligibility message.

  5. Otherwise, the program displays a message indicating that the player is not eligible.

Example Output

Case 1

Enter the age:24
Sorry You cant play

Case 2

Enter the age:16
You are Eligible to play in College Cricket:

Project Structure

college-cricket-eligibility/
│
├── main.py
└── README.md

Requirements

  • Python 3.x

How to Run

  1. Install Python 3 if it is not already installed.

  2. Download or clone this repository.

  3. Open a terminal in the project folder.

  4. Run the following command:

python main.py
  1. Enter your age when prompted.

Concepts Used

  • Variables

  • User input

  • Integer conversion

  • if-else statements

  • Comparison operators

  • Logical operators (not and and)

Purpose

This project is designed for beginners who are learning Python programming and conditional statements.

6. GitHub 專案檔案結構

college-cricket-eligibility/

main.py

Python 主程式

README.md

專案說明文件

這樣就完成一個基本的 Python GitHub 專案。你可以把 main.py 和 README.md 上傳至同一個 Repository,方便展示程式碼與學習成果。

留言

這個網誌中的熱門文章

HW02 運算子表達式