notebooklm

學習卡














1. Project structure

text
leap-year-checker/
├── leap_year.py
└── README.md

2. Python program — leap_year.py

python

# Leap Year Checker

year = int(input("Enter a year: "))

if year % 400 == 0:
    print(f"{year} is a leap year.")
elif year % 100 == 0:
    print(f"{year} is not a leap year.")
elif year % 4 == 0:
    print(f"{year} is a leap year.")
else:
    print(f"{year} is not a leap year.")

How it works

A year is a leap year if:

  • It is divisible by 400, or

  • It is divisible by 4 but not divisible by 100.

Examples:

text
Enter a year: 2024
2024 is a leap year.
text
Enter a year: 1900
1900 is not a leap year.
text
Enter a year: 2000
2000 is a leap year.

3. GitHub README — README.md

Create a file named README.md in your project folder and copy the following content.

寫作

🗓️ Leap Year Checker

A simple Python program that prompts the user to enter a year and determines whether it is a leap year.

📌 About the Project

This project is a beginner-friendly Python exercise designed to practice user input, conditional statements, and arithmetic operators.

✨ Features

  • Accepts a year from the user.
  • Checks whether the year is a leap year.
  • Displays a clear result.
  • Uses simple Python conditional statements.

🛠️ Built With

  • Python 3

📂 Project Structure

leap-year-checker/
├── leap_year.py
└── README.md

🚀 Getting Started

Prerequisites

Install Python 3 on your computer.

Check your Python installation by running:

python --version

Installation

  1. Clone this repository:
   git clone https://github.com/YOUR-USERNAME/leap-year-checker.git
  1. Navigate to the project directory:
   cd leap-year-checker
  1. Run the Python program:
   python leap_year.py

💻 Usage

Enter a year when prompted by the program.

Example:

Enter a year: 2024
2024 is a leap year.

Another example:

Enter a year: 1900
1900 is not a leap year.

📖 Leap Year Rules

A year is a leap year if:

  • It is divisible by 400; or
  • It is divisible by 4 but not divisible by 100.

For example:

YearResult
2024Leap year
2023Not a leap year
1900Not a leap year
2000Leap year

🎯 Learning Objectives

  • Understand Python's input() function.
  • Convert user input into an integer using int().
  • Use if, elif, and else statements.
  • Apply the modulo operator (%) to check divisibility.

🤝 Contributing

Contributions, suggestions, and improvements are welcome. Feel free to fork this repository and submit a pull request.

📄 License

This project is available under the MIT License. Add a LICENSE file to the repository if you wish to distribute it under that license.

👤 Author

YOUR NAME

GitHub: @YOUR-USERNAME

4. Upload the project to GitHub

  1. Create a new repository on .

  2. Name it leap-year-checker.

  3. Add leap_year.py and README.md to your project.

  4. Commit and push the files to your repository.

If you're uploading through Git, run these commands inside your project folder:

bash
git init
git add leap_year.py README.md
git commit -m "Add leap year checker"
git branch -M main
git remote add origin https://github.com/YOUR-USERNAME/leap-year-checker.git
git push -u origin main

Replace YOUR-USERNAME with your GitHub username.

Tip: Before publishing, replace the author placeholders in the README with your own details.

留言

這個網誌中的熱門文章