{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "n = 0\n", "\n", "while n < 11:\n", " print('Number is ', n)\n", " n += 1\n", " print('===', n)\n", "print('End of Loop')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "n = 10\n", "\n", "while n > -1:\n", " print('Number is ', n)\n", " n -=1\n", "print('End of Loop')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "my_list = ['ham', 'egg', 'bacon']\n", "\n", "while my_list:\n", " print(my_list.pop())\n", " print('We are in the loop')\n", " print(my_list)\n", "print('End of the Loop')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "my_list" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "n = 5\n", "\n", "while n > 0:\n", " n -=1\n", " print(n)\n", "print('End of Loop')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "n = 5\n", "\n", "while n > 0:\n", " n -=1\n", " if n % 3 == 0:\n", " break\n", " print(n)\n", " print('In the loop')\n", "print('End of Loop')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "n = 5\n", "\n", "while n > 0:\n", " n -=1\n", " if n % 3 == 0:\n", " continue\n", " print(n)\n", " print('In the loop')\n", "print('End of Loop')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "n = 5\n", "\n", "while n > 0:\n", " n -=1\n", " print(n)\n", "else:\n", " print('End of Loop')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "n = 5\n", "\n", "while n > 0:\n", " n -=1\n", " if n % 3 == 0:\n", " break\n", " print(n)\n", " print('In the loop')\n", "else:\n", " print('End of Loop')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "l = ['a', 'b', 'c', 'd']\n", "s = 'z'\n", "\n", "i = 0\n", "while i < len(l):\n", " if l[i] == s:\n", " print(i)\n", " break\n", " i +=1\n", "else:\n", " print(s, ' is not found')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import random" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lower = int(input(\"Enter lower bound - \"))\n", "upper = int(input(\"Enter upper bound - \"))\n", "\n", "x = random.randint(lower, upper)\n", "chances = 10\n", "print(\"\\n\\t You've only \", chances, \" chances to guess the interger!\\n\")\n", "\n", "count = 0\n", "while count< chances:\n", " count += 1\n", " guess = int(input(\"Guess a number :- \"))\n", " if x == guess:\n", " print(\"Congratulations you did it in \", count, \" tries.\")\n", " break\n", " elif x > guess:\n", " print(\"Try Again! Number is too small.\")\n", " else:\n", " print(\"Try Again! Number is too big.\")\n", "else:\n", " print(\"\\nThe number is \", x, \".\\n\\tBetter Luck Next Time!\")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "c\n", "> e\n", "> d\n" ] } ], "source": [ "l1 = ['a', 'b', 'c']\n", "while len(l1):\n", " print(l1.pop())\n", " l2 = ['d', 'e']\n", " while len(l2):\n", " print('>', l2.pop())\n", " break" ] } ], "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.8.3" } }, "nbformat": 4, "nbformat_minor": 4 }