Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

{

"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 0
},
"id": "MbLiCU1dyLMU",
"outputId": "565bd43e-0076-4176-8fae-7cc20a70b76a"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"PLease enter amount with currency symbol: $100\n",
"You have to pay $85.0 after discount\n",
"Final Price: $85.0\n",
"\n",
"\n",
"\n",
"\n",
"You have to pay $85.0 after discount\n",
"Final Price: $85.0\n"
]
}
],
"source": [
"#Simple method : without checking currency symbol \n",
"#Issue with this approach is that if we dot enter currency symbol it will
return wrong result.\n",
"price = input(\"PLease enter amount with currency symbol: \")\n",
"price1 = int(price[1:])\n",
"price2 = price[:1]+str(price1*0.85)\n",
"print(\"You have to pay \",price2,\" after discount\")\n",
"print(\"Final Price:\",price2)\n",
"\n",
"print(\"\\n\\n\\n\")\n",
"#Using try & Except here we are checking prefix (Currency symbol)\n",
"try:\n",
" int(price[0])\n",
" print(\"Please enter amount using currency symbol\")\n",
"except:\n",
" price1 = int(price[1:])\n",
" price2 = price[:1]+str(price1*0.85)\n",
" print(\"You have to pay \",price2,\" after discount\")\n",
" print(\"Final Price:\",price2)\n",
" "
]
}
]
}

You might also like