{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "24697664", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "My name is Syed Usman Ghani. I am 37 years old and I live in Pakistan\n" ] } ], "source": [ "name = \"Syed Usman Ghani\"\n", "age = 37\n", "country = \"Pakistan\"\n", "\n", "my_info = \"My name is \"+name+\\\n", "\". I am \"+str(age)+\\\n", "\" years old and I live in \"+country\n", "\n", "print(my_info)" ] }, { "cell_type": "code", "execution_count": 8, "id": "f963df30", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "I bought 100 iphone14 Pro Max(s) at $6500 each,for a total of $650000\n", "\n" ] } ], "source": [ "item = \"iphone14 Pro Max\"\n", "price = 6500\n", "quantity = 100\n", "\n", "total_cost = price * quantity\n", "\n", "stat = \"\"\"\n", "I bought {0}\\\n", " {1}(s) at ${2} each,\\\n", "for a total of ${3}\n", "\"\"\".format(quantity,item,price,total_cost)\n", "\n", "print(stat)" ] }, { "cell_type": "code", "execution_count": 3, "id": "62f6629c", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The temperature in Karachi is 27°C.\n" ] } ], "source": [ "city = \"Karachi\"\n", "temperature = 27\n", "\n", "print(f\"The temperature in {city} is {temperature}°C.\")" ] }, { "cell_type": "code", "execution_count": 4, "id": "5c376828", "metadata": {}, "outputs": [ { "ename": "TypeError", "evalue": "format requires a mapping", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", "Cell \u001b[1;32mIn[4], line 8\u001b[0m\n\u001b[0;32m 4\u001b[0m current_year \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m2023\u001b[39m\n\u001b[0;32m 6\u001b[0m age \u001b[38;5;241m=\u001b[39m current_year \u001b[38;5;241m-\u001b[39m birth_year\n\u001b[1;32m----> 8\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMy name is \u001b[39m\u001b[38;5;132;01m%(first_name)s\u001b[39;00m\u001b[38;5;124m \u001b[39m\u001b[38;5;132;01m%(last_name)s\u001b[39;00m\u001b[38;5;124m. I am \u001b[39m\u001b[38;5;132;01m%(age)d\u001b[39;00m\u001b[38;5;124m years old.\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;241m%\u001b[39m(first_name,last_name,age))\n", "\u001b[1;31mTypeError\u001b[0m: format requires a mapping" ] } ], "source": [ "first_name = \"Syed Usman\"\n", "last_name = \"Ghani\"\n", "birth_year = 1986\n", "current_year = 2023\n", "\n", "age = current_year - birth_year\n", "\n", "print(\"My name is %(first_name)s %(last_name)s. I am %(age)d years old.\" %(first_name,last_name,age))" ] }, { "cell_type": "code", "execution_count": 5, "id": "75bc409b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "My name is Syed Usman Ghani. I am 37 years old.\n" ] } ], "source": [ "first_name = \"Syed Usman\"\n", "last_name = \"Ghani\"\n", "birth_year = 1986\n", "current_year = 2023\n", "\n", "age = current_year - birth_year\n", "\n", "mapping = {\"first_name\": first_name, \"last_name\": last_name, \"age\": age}\n", "\n", "print(\"My name is %(first_name)s %(last_name)s. I am %(age)d years old.\" %mapping)" ] }, { "cell_type": "code", "execution_count": 6, "id": "4df0d69c", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "LIMITED TIME OFFER! Apple Macbook M-3 machine which originally costs $2000 is now available at Flat 25% OFF. Now Apple Macbook M-3 will cost you just $1500. Hurry up and GRAB the offer\n", "\n" ] } ], "source": [ "product = \"Apple Macbook M-3\"\n", "discount = 25\n", "original_price = 2000\n", "\n", "discounted_price = int(original_price * (1 - discount/100))\n", "\n", "offer = f\"\"\"\n", "LIMITED TIME OFFER! {product} machine which originally costs ${original_price}\\\n", " is now available at Flat {discount}% OFF. Now {product} will cost you just ${discounted_price}.\\\n", " Hurry up and GRAB the offer\n", "\"\"\"\n", "\n", "print(offer)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.11.3" } }, "nbformat": 4, "nbformat_minor": 5 }