{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e0a63fab-c721-4c32-9e1e-6424b655f610",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "斐波那契数列前10项：\n",
      "1、1、2、3、5、8、13、21、34、55\n"
     ]
    }
   ],
   "source": [
    "def fibonacci(n):\n",
    "    \"\"\"\n",
    "    递归计算斐波那契数列第n项\n",
    "    param n: 项数 (正整数)\n",
    "    return: 第n项的值 ( int )\n",
    "    \"\"\"\n",
    "    # 递归出口：第1、2项为 1\n",
    "    if n == 1 or n == 2:\n",
    "        return 1\n",
    "    else:\n",
    "        # 递归公式：第n项 = 第n-1项 + 第n-2项\n",
    "        return fibonacci(n - 1) + fibonacci(n - 2)\n",
    "\n",
    "# 输出前10项\n",
    "print(\"斐波那契数列前10项：\")\n",
    "fib_list = []\n",
    "for i in range(1, 11):\n",
    "    fib_list.append(str(fibonacci(i)))  # 转为字符串，便于拼接\n",
    "print(\"、\".join(fib_list))  # 用 \"、\"连接列表元素"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6104c45d-e18b-4c8e-bc8b-b716f4a2572c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python (tensorflow)",
   "language": "python",
   "name": "py39_env"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
