{"id":33526,"date":"2021-05-11T11:35:49","date_gmt":"2021-05-11T09:35:49","guid":{"rendered":"https:\/\/eiposgrados.com\/?p=33526"},"modified":"2021-05-11T11:55:44","modified_gmt":"2021-05-11T09:55:44","slug":"how-to-make-python-calculator","status":"publish","type":"post","link":"https:\/\/eiposgrados.com\/eng\/python-blog\/how-to-make-python-calculator\/","title":{"rendered":"Your first calculator in Python"},"content":{"rendered":"<h2 class=\"wp-block-heading\">How to make a calculator in Python?<\/h2>\n\n\n\n<p>Last week we talked to you about the<a href=\"https:\/\/eiposgrados.com\/eng\/python-blog\/how-to-make-a-while-loop-in-python\/\" class=\"rank-math-link\"> while loops in Python<\/a>, its characteristics and operation. Well, this week <strong>let&#039;s make use of them<\/strong> and we are going to schedule a simple <strong>calculator<\/strong> to practice. <\/p>\n\n\n\n<p>If you want to continue learning about programming you can do so at <a href=\"https:\/\/eiposgrados.com\/eng\/\" class=\"rank-math-link\">EIP<\/a> with our <a href=\"https:\/\/eiposgrados.com\/eng\/master-in-python\/\">master in Advanced Programming in Python for Big Data, Hacking and Machine Learning<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"468\" src=\"https:\/\/eiposgrados.com\/wp-content\/uploads\/2021\/05\/Captura-de-pantalla-2021-05-11-a-las-11.15.44-1024x468.png\" alt=\"how to make a calculator in python\" class=\"wp-image-33527\" title=\"\" srcset=\"https:\/\/eiposgrados.com\/wp-content\/uploads\/2021\/05\/Captura-de-pantalla-2021-05-11-a-las-11.15.44-1024x468.png 1024w, https:\/\/eiposgrados.com\/wp-content\/uploads\/2021\/05\/Captura-de-pantalla-2021-05-11-a-las-11.15.44-300x137.png 300w, https:\/\/eiposgrados.com\/wp-content\/uploads\/2021\/05\/Captura-de-pantalla-2021-05-11-a-las-11.15.44-768x351.png 768w, https:\/\/eiposgrados.com\/wp-content\/uploads\/2021\/05\/Captura-de-pantalla-2021-05-11-a-las-11.15.44.png 1392w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>  <\/figcaption><\/figure>\n\n\n\n<p>We begin by collecting the two numbers with which our<strong> calculator<\/strong> is going to work, we create a variable for the selection of the operation that we want our calculator to perform and<strong> we create our loop<\/strong> with the list of options where the condition would be the user&#039;s choice to exit the program by pressing option 6.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"456\" src=\"https:\/\/eiposgrados.com\/wp-content\/uploads\/2021\/05\/Captura-de-pantalla-2021-05-11-a-las-11.16.31-1024x456.png\" alt=\"\" class=\"wp-image-33529\" title=\"\" srcset=\"https:\/\/eiposgrados.com\/wp-content\/uploads\/2021\/05\/Captura-de-pantalla-2021-05-11-a-las-11.16.31-1024x456.png 1024w, https:\/\/eiposgrados.com\/wp-content\/uploads\/2021\/05\/Captura-de-pantalla-2021-05-11-a-las-11.16.31-300x134.png 300w, https:\/\/eiposgrados.com\/wp-content\/uploads\/2021\/05\/Captura-de-pantalla-2021-05-11-a-las-11.16.31-768x342.png 768w, https:\/\/eiposgrados.com\/wp-content\/uploads\/2021\/05\/Captura-de-pantalla-2021-05-11-a-las-11.16.31.png 1432w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>   <\/figcaption><\/figure>\n\n\n\n<p>After in <strong>operation function <\/strong>that you want to perform, would fall within one option or another of our &#039;if&#039; or &#039;elif&#039; conditional statements.<\/p>\n\n\n\n<p>In option 4, division we convert the result into <em><strong>float<\/strong><\/em> to be able to print decimals, since otherwise it will only print the integer part, ignoring all decimals.<\/p>\n\n\n\n<p>We are going to<strong> put it to the test,<\/strong>\u00a0We enter the numbers 7 and 3.<\/p>\n\n\n\n<p><img decoding=\"async\" width=\"252\" height=\"173\" src=\"https:\/\/lh4.googleusercontent.com\/-nwoJvpEhMjwBts_DOutLbKpTKEiO2fRDE-1tojyY9VL20kUFOQnuPseK4VcGkescp4INSp2vVc-dW6Inn0SfXWWKJsp1hfZ_4LxdipEyKv306iQNUX3RaN4mLh8bKI74-p2AqGkVofH6oNnvg\" alt=\"\" title=\"\"><\/p>\n\n\n\n<p>Let&#039;s add them up, so we mark option 1 of our fantastic <strong>calculator<\/strong> and since we are wonderful programmers, it prints the line with the result of the sum, 7 + 3 = 10.<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" width=\"254\" height=\"195\" src=\"https:\/\/lh4.googleusercontent.com\/LSPeDZ1JDXrur071xF3ob6weevDjMJJkQ0CUm5iM7K3GkQM2c80fS7LCj9Kjrzh4iYWCPwjS5b_DGAxbWTC6CUOnB7baeu9WB6A2eiqrjjsERFlljFgpwb7Be5B3aOk5EVHWfUxtCOj5I7irew\" alt=\"\" title=\"\"><\/p>\n\n\n\n<p>We try the rest of the operations and we see that they all work like a charm.<\/p>\n\n\n\n<p><br><img loading=\"lazy\" decoding=\"async\" width=\"296\" height=\"68\" src=\"https:\/\/docs.google.com\/drawings\/u\/0\/d\/s9wCP_7_0aJSG9HbBXK3mpQ\/image?w=296&amp;h=68&amp;rev=1&amp;ac=1&amp;parent=1MK7OCWWjKA2bDBdNkOLRojmg_jMlxIWUBjB5o708Lw8\" alt=\"\" title=\"\"><\/p>\n\n\n\n<p>The <strong>option 5<\/strong> It allows us to change the numbers to work with.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/gTkpXV-mSa2579STL4e46cVIz8wndmLrxislKGHW391R4vyZNUlRTevh2vNTAslL8LKQBU71qXmQ6y_PLyFsznN-yTH8QgxtjeRH-vDjks-v0h3bwDq300tbWVEdlgKq04A_fFVu-dikLpbfmQ\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<p>And the last option turns off our calculator by printing the <strong>goodbye message.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/mJIhjAV87yGjDM8gSnna5ZWDkni7pCHLrMIerWGcTKHxpRC6tONXfPs5Q2SLcxRS8gHxSxeeIKss9dJJz_zXTRn2adqGJow8OZdygGY2uOZ_PZwyu2Bm37Aydm9uXKtA8trr7EkeB0Jho-rI9Q\" alt=\"\" title=\"\"><\/figure>","protected":false},"excerpt":{"rendered":"<p>How to make a calculator in Python? We explain the steps you must follow and give you an example so you can make your first calculator. Do not miss it! <\/p>","protected":false},"author":51,"featured_media":33532,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[407],"tags":[],"class_list":["post-33526","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-python"],"acf":[],"_links":{"self":[{"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/posts\/33526","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/users\/51"}],"replies":[{"embeddable":true,"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/comments?post=33526"}],"version-history":[{"count":0,"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/posts\/33526\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/media\/33532"}],"wp:attachment":[{"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/media?parent=33526"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/categories?post=33526"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/tags?post=33526"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}