|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "51378663", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "# Switch Statement in Python\n", |
| 9 | + "## For python Version 3.10 and after Switch statement is supported\n", |
| 10 | + "We can Implement it using match and case" |
| 11 | + ] |
| 12 | + }, |
| 13 | + { |
| 14 | + "cell_type": "code", |
| 15 | + "execution_count": 4, |
| 16 | + "id": "015e974a", |
| 17 | + "metadata": {}, |
| 18 | + "outputs": [ |
| 19 | + { |
| 20 | + "name": "stdout", |
| 21 | + "output_type": "stream", |
| 22 | + "text": [ |
| 23 | + "Programming Language you entered is: Python\n", |
| 24 | + "High Level Programming Language\n" |
| 25 | + ] |
| 26 | + } |
| 27 | + ], |
| 28 | + "source": [ |
| 29 | + "# Implementing Switch case\n", |
| 30 | + "\n", |
| 31 | + "# Taking User Input\n", |
| 32 | + "prog=input(\"Enter Programming Language: \")\n", |
| 33 | + "# Printing User input\n", |
| 34 | + "print(\"Programming Language you entered is: \",prog)\n", |
| 35 | + "\n", |
| 36 | + "# Switch Case is implemented using match and case\n", |
| 37 | + "match prog:\n", |
| 38 | + "\n", |
| 39 | + " # Adding cases\n", |
| 40 | + " case 'C':\n", |
| 41 | + " print(\"Middle Level Programming Language\")\n", |
| 42 | + " case 'Python':\n", |
| 43 | + " print(\"High Level Programming Language\")\n", |
| 44 | + " case 'R':\n", |
| 45 | + " print(\"High Level Programming Language\")\n", |
| 46 | + "\n", |
| 47 | + " # This will execute if no case is matched\n", |
| 48 | + " case default:\n", |
| 49 | + " print('Not a Valid Programming Language') " |
| 50 | + ] |
| 51 | + }, |
| 52 | + { |
| 53 | + "cell_type": "code", |
| 54 | + "execution_count": null, |
| 55 | + "id": "c5d3758f", |
| 56 | + "metadata": {}, |
| 57 | + "outputs": [], |
| 58 | + "source": [] |
| 59 | + } |
| 60 | + ], |
| 61 | + "metadata": { |
| 62 | + "kernelspec": { |
| 63 | + "display_name": "Python 3 (ipykernel)", |
| 64 | + "language": "python", |
| 65 | + "name": "python3" |
| 66 | + }, |
| 67 | + "language_info": { |
| 68 | + "codemirror_mode": { |
| 69 | + "name": "ipython", |
| 70 | + "version": 3 |
| 71 | + }, |
| 72 | + "file_extension": ".py", |
| 73 | + "mimetype": "text/x-python", |
| 74 | + "name": "python", |
| 75 | + "nbconvert_exporter": "python", |
| 76 | + "pygments_lexer": "ipython3", |
| 77 | + "version": "3.10.4" |
| 78 | + } |
| 79 | + }, |
| 80 | + "nbformat": 4, |
| 81 | + "nbformat_minor": 5 |
| 82 | +} |
0 commit comments