Spaces:
No application file
No application file
File size: 5,644 Bytes
5d07f20 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
{
"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)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7838c1c6",
"metadata": {},
"outputs": [],
"source": [
"first_name = \"FirstName\"\n",
"last_name = \"LastName\"\n",
"birth_year = 2003\n",
"current_year = 2023\n",
"\n",
"age = current_year - birth_year\n",
"\n",
"formatted_string = \"My name is %(first_name)s %(last_name)s. I am %(age)d\" %{}"
]
}
],
"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
}
|