{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### Q2" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "ename": "KeyError", "evalue": "'test'", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[1], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28mdict\u001b[39m \u001b[38;5;241m=\u001b[39m {\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mRafay\u001b[39m\u001b[38;5;124m'\u001b[39m : \u001b[38;5;241m3.3\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mHassan\u001b[39m\u001b[38;5;124m'\u001b[39m : \u001b[38;5;241m3.7\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mIsham\u001b[39m\u001b[38;5;124m'\u001b[39m : \u001b[38;5;241m4.8\u001b[39m}\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;28;43mdict\u001b[39;49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mtest\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m)\n", "\u001b[0;31mKeyError\u001b[0m: 'test'" ] } ], "source": [ "dict = {'Rafay' : 3.3, 'Hassan' : 3.7, 'Isham' : 4.8}\n", "key = 'test'\n", "if dict.get(key) is None :\n", " print('key does not exist')\n", "else:\n", " print('key exists')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Q3" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "basicPay = int(input('Enter basic pay'))\n", "\n", "if basicPay < 30000 :\n", " houseRent = 0.3 * basicPay\n", "elif basicPay >= 30000 and basicPay <= 50000 :\n", " houseRent = 0.4 * basicPay\n", "else:\n", " houseRent = 0.5 * basicPay\n", "\n", "netPay = basicPay + houseRent\n", "\n", "print('Basic Pay', basicPay)\n", "print('House Rent', houseRent)\n", "print('Net Pay', netPay)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Q4" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "num1 = input('Enter first number: ')\n", "num2 = input('Enter second number: ')\n", "num3 = input('Enter third number: ')\n", "\n", "\n", "\n", "print()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Q5" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.12.4" } }, "nbformat": 4, "nbformat_minor": 2 }