{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 控制语句执行流程"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "please input your score99\n",
      "your score is great.\n"
     ]
    }
   ],
   "source": [
    "a = input('please input your score')\n",
    "floata  = float(a)\n",
    "if floata < 60:\n",
    "    print('your score is low')\n",
    "elif 60 <= floata <= 90:\n",
    "    print('your score is normal')\n",
    "else:\n",
    "    print('your score is great.')\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "BBB<<< value\n"
     ]
    }
   ],
   "source": [
    "dicts  = {}\n",
    "dicts.setdefault('a',\"AAA\")\n",
    "dicts.setdefault('b',\"BBB\")\n",
    "dicts.setdefault('c',\"CCC\")\n",
    "dictsItem = dicts.keys();\n",
    "for key in dictsItem:\n",
    "    if key == 'a':\n",
    "        continue\n",
    "    if key == 'c':\n",
    "        break\n",
    "    print(dicts.get(key) + \"<<< value\")\n",
    "else:\n",
    "    print('item is done.')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "AAA<<< value\n",
      "BBB<<< value\n"
     ]
    }
   ],
   "source": [
    "dicts  = {}\n",
    "dicts.setdefault('a',\"AAA\")\n",
    "dicts.setdefault('b',\"BBB\")\n",
    "dicts.setdefault('c',\"CCC\")\n",
    "\n",
    "for key ,value in dicts.items():\n",
    "    if key == 'a':\n",
    "        print(value + \"<<< value\")\n",
    "        continue\n",
    "    if key == 'c':\n",
    "        break\n",
    "    print(value + \"<<< value\")\n",
    "else:\n",
    "    print('item is done.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n",
      "10\n",
      "11\n",
      "12\n",
      "13\n",
      "14\n",
      "15\n",
      "16\n",
      "17\n",
      "18\n",
      "19\n",
      "20\n",
      "21\n",
      "22\n",
      "23\n",
      "24\n",
      "25\n",
      "26\n",
      "27\n",
      "28\n",
      "29\n",
      "30\n",
      "31\n",
      "32\n",
      "33\n",
      "34\n",
      "35\n",
      "36\n",
      "37\n",
      "38\n",
      "39\n",
      "40\n",
      "41\n",
      "42\n",
      "43\n",
      "44\n",
      "45\n",
      "46\n",
      "47\n",
      "48\n",
      "49\n",
      "50\n",
      "51\n",
      "52\n",
      "53\n",
      "54\n",
      "55\n",
      "56\n",
      "57\n",
      "58\n",
      "59\n",
      "60\n",
      "61\n",
      "62\n",
      "63\n",
      "64\n",
      "65\n",
      "66\n",
      "67\n",
      "68\n",
      "69\n",
      "70\n",
      "71\n",
      "72\n",
      "73\n",
      "74\n",
      "75\n",
      "76\n",
      "77\n",
      "78\n",
      "79\n",
      "80\n",
      "81\n",
      "82\n",
      "83\n",
      "84\n",
      "85\n",
      "86\n",
      "87\n",
      "88\n",
      "89\n",
      "90\n",
      "91\n",
      "92\n",
      "93\n",
      "94\n",
      "95\n",
      "96\n",
      "97\n",
      "98\n",
      "99\n"
     ]
    }
   ],
   "source": [
    "for i in range(5):\n",
    "    print(i)\n",
    "for k in range(0,100):\n",
    "    print(k)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "please input a num78\n",
      "please input a num87\n",
      "79 是素数！ hahaha\n",
      "83 是素数！ hahaha\n"
     ]
    }
   ],
   "source": [
    "x = (input('please input a num'),input('please input a num'))\n",
    "x1 = int(min(x))\n",
    "x2 = int(max(x))\n",
    "for n in range(x1,x2+1):\n",
    "    for i in range(2,n-1):\n",
    "        if n % i == 0:\n",
    "            break;\n",
    "    else:\n",
    "        print(n,'是素数！','hahaha')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 h\n",
      "1 a\n",
      "2 h\n",
      "3 a\n",
      "4 h\n",
      "5 a\n",
      "0 2\n",
      "1 5\n",
      "2 7\n",
      "3 9\n",
      "4 1\n",
      "(2, 2)\n",
      "(5, 5)\n",
      "(7, 7)\n",
      "(9, 9)\n"
     ]
    }
   ],
   "source": [
    "for i,item in enumerate('hahaha'):\n",
    "    print(i,item)\n",
    "lists = [2,5,7,9,1]\n",
    "for i,item in enumerate(lists):\n",
    "    print(i,item)\n",
    "lists2 = [2,5,7,9]\n",
    "for i in zip(lists,lists2):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "while end.\n"
     ]
    }
   ],
   "source": [
    "lists = [1,5,7,9,11]\n",
    "total = len(lists)\n",
    "i = 0\n",
    "while i < total:\n",
    "    print(i)\n",
    "    i += 1\n",
    "else:\n",
    "    print('while end.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 9, 25, 49, 81]"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lists = [i**2 for i in range(0,10)]\n",
    "lists\n",
    "\n",
    "keys = ['name','age','weight']\n",
    "values = ['bob','23','68']\n",
    "dicts = {k:v for k,v in zip(keys,values)}\n",
    "dicts\n",
    "\n",
    "lists2 = [i**2 for i in range(0,10,1) if i % 2 == 1]\n",
    "lists2"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "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.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
