{"id":3582,"date":"2020-05-02T23:35:41","date_gmt":"2020-05-02T14:35:41","guid":{"rendered":"https:\/\/katblog.manadream.net\/?p=3582"},"modified":"2020-09-30T00:07:07","modified_gmt":"2020-09-29T15:07:07","slug":"lets-calculate","status":"publish","type":"post","link":"https:\/\/katblog.manadream.net\/index.php\/2020\/05\/02\/lets-calculate\/","title":{"rendered":"[PHP]Let&#8217;s Calculate![Programming for Kids and Above #3]"},"content":{"rendered":"<p>Hello, I&#8217;m kat, the manager of &#8216;kat&#8217;s blog.<\/p>\n<p>&#8216;For the third installment of [Programming for Kids and Above], we will cover how to add, subtract, multiply, and divide in programming.<\/p>\n<p><span class=\"marker\">Calculations are the specialty of computers.<\/span><\/p>\n<p>Even calculations that would take a long time for a human to solve, <span class=\"marker\">computers can do it in an instant.<\/span><\/p>\n\n\n<h2 class=\"wp-block-heading\"> Why are computers fast?<\/h2>\n\n\n<p>Why is it that computers are so fast at doing calculations?<\/p>\n<p>That is because, there is electricity flowing inside the computer, and that electricity is doing the calculations such as addition.<\/p>\n<p>It is said that the speed of electricity is the same as the speed of light, and it is so fast that it cannot be seen by the naked eye.<\/p>\n<p>This speed enables it to do calculations in an instant.<\/p>\n\n\n<h2 class=\"wp-block-heading\"><strong>What we will use this time<\/strong><\/h2>\n\n\n<p><div class=\"kaisetsu-box4\"><div class=\"kaisetsu-box4-title\">The programming language we will use this time<\/div><p><\/p>\n<p>This time we will use the following programming language to write out a program.<\/p>\n<div class=\"simple-box7\">\n<p>\u30fbPHP<\/p>\n<\/div>\n<p><\/p><\/div><\/p>\n\n\n<h2 class=\"wp-block-heading\">Let&#8217;s calculate!<\/h2>\n\n\n<p>Let&#8217;s go ahead and write out a program.<\/p>\n<p>This time, we will be programming on a website called &#8216;paiza.&#8217;<\/p>\n<p>First, let&#8217;s display the website by clicking the link below.<\/p>\n<p><span class=\"twobutton\"><span class=\"color-button02\"><a href=\"https:\/\/paiza.io\/en\/projects\/new?locale=en-us\" target=\"_blank\" rel=\"noopener noreferrer\">paiza website<\/a><\/span><\/span><\/p>\n<p>Once the website is displayed, check to make sure that the button on the top left is showing as &#8216;PHP.&#8217;<\/p>\n<p>If it hasn&#8217;t changed, choose &#8216;PHP.&#8217;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3552\" data-permalink=\"https:\/\/katblog.manadream.net\/index.php\/2020\/04\/22\/lets-display-letters\/paiza-php-en\/\" data-orig-file=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/04\/paiza-php-en.png\" data-orig-size=\"2062,1014\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"paiza-php-en\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/04\/paiza-php-en-300x148.png\" data-large-file=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/04\/paiza-php-en-1024x504.png\" class=\"alignnone size-large wp-image-3552\" src=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/04\/paiza-php-en-1024x504.png\" alt=\"\" width=\"1024\" height=\"504\" srcset=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/04\/paiza-php-en-1024x504.png 1024w, https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/04\/paiza-php-en-300x148.png 300w, https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/04\/paiza-php-en-768x378.png 768w, https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/04\/paiza-php-en-1536x755.png 1536w, https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/04\/paiza-php-en-2048x1007.png 2048w, https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/04\/paiza-php-en-1024x504.png 856w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p>Once you reach this stage, you are ready for the programming.<\/p>\n\n\n<h2 class=\"wp-block-heading\">Addition<\/h2>\n\n\n<p>After writing in the source code, click the &#8216;Run (Ctrl-Enter)&#8217; button like the following image.<\/p>\n<p>Then the result will be displayed.<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\n  \n \/\/ addition\n $result = 1 + 2;\n echo 'calculation result\uff1a' . $result;\n<\/pre><\/div>\n\n<p>Once you are done entering the necessary information, click the &#8216;Run&#8217; button on the bottom left.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3604\" data-permalink=\"https:\/\/katblog.manadream.net\/index.php\/2020\/05\/02\/lets-calculate\/paiza-input2-en\/\" data-orig-file=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/05\/paiza-input2-en.png\" data-orig-size=\"1806,1386\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"paiza-input2-en\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/05\/paiza-input2-en-300x230.png\" data-large-file=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/05\/paiza-input2-en-1024x786.png\" class=\"alignnone size-large wp-image-3604\" src=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/05\/paiza-input2-en-1024x786.png\" alt=\"\" width=\"1024\" height=\"786\" srcset=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/05\/paiza-input2-en-1024x786.png 1024w, https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/05\/paiza-input2-en-300x230.png 300w, https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/05\/paiza-input2-en-768x589.png 768w, https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/05\/paiza-input2-en-1536x1179.png 1536w, https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/05\/paiza-input2-en.png 1806w, https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/05\/paiza-input2-en-1024x786.png 856w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p>If letters saying, &#8216;calculation result:3&#8217; appear, then it is a success!<\/p>\n<p>Let me give a brief explanation about the program.<\/p>\n<p><div class=\"kaisetsu-box3\"><div class=\"kaisetsu-box3-title\">~Explanation 1~<\/div><p><\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\n<\/pre><\/div>\n\n<p>This means the start of a PHP program.<\/p>\n<p>It is a rule to always put &#8216;&lt;?php&#8217; at the beginning of a PHP program.<\/p>\n<p><\/p><\/div><\/p>\n<p><div class=\"kaisetsu-box3\"><div class=\"kaisetsu-box3-title\">~Explanation 2~<\/div><p><\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; first-line: 4; title: ; notranslate\" title=\"\">\n$result = 1 + 2;\n<\/pre><\/div>\n\n<p>Here, we will be adding numbers.<\/p>\n<p>&#8216;$result&#8217; is something that is called a variable.<\/p>\n<p>A variable is like a container, so you can put the value that is written after the &#8216;= (equal sign)&#8217; into it.<\/p>\n<p>Here, we put the result (&#8216;3&#8217;) of &#8216;1+2&#8217; into the &#8216;$result&#8217; variable (container).<\/p>\n<div class=\"kaisetsu-box4\"><div class=\"kaisetsu-box4-title\">\u2713 Point<\/div><p><\/p>\n<p><em>In the case of PHP, there is a rule to <span class=\"marker\">always put a &#8216;$ (dollar)&#8217; sign at the beginning of a variable<\/span>.<\/em><\/p>\n<p><em>You can decide freely which letters come after the &#8216;$&#8217; sign.<\/em><\/p>\n<p><em>Let&#8217;s try making variables with a name of your choice such as, &#8216;$message,&#8217; &#8216;$color.&#8217;<\/em><\/p>\n<p><\/p><\/div>\n<p><\/p><\/div><\/p>\n<p><div class=\"kaisetsu-box3\"><div class=\"kaisetsu-box3-title\">~Explanation 3~<\/div><p><\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; first-line: 5; title: ; notranslate\" title=\"\">\necho 'calculation result\uff1a' . $result;\n<\/pre><\/div>\n\n<p>Here, the calculation result is displayed on the screen.<\/p>\n<p>The letters written after &#8216;echo,&#8217; will be displayed on the screen.<\/p>\n<p>The &#8216;.&#8217; after &#8216;calculation result:&#8217;, is used to connect letters to letters (or variables).<\/p>\n<p>Here it is connecting &#8216;calculation result:&#8217; , and &#8216;$result&#8217;.<\/p>\n<p>Because the calculation result from earlier (&#8220;&#8221;3&#8243;&#8221;) is in the &#8216;$result&#8217;, &#8216;calculation result:&#8217; and &#8216;the value of $result(&#8220;&#8221;3&#8243;&#8221;)&#8217; are connected, and &#8216;calculation result:3&#8217; is displayed on the screen.<\/p>\n<p><\/p><\/div><\/p>\n\n\n<h2 class=\"wp-block-heading\">Subtraction<\/h2>\n\n\n<p>Next, let&#8217;s try some subtractions.<\/p>\n<p>Enter the following into the source code input area.<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\n\n \/\/ subtract\n $result = 3 - 2;\n echo 'calculation result\uff1a' . $result;\n<\/pre><\/div>\n\n<p>Once you finish entering, click the &#8216;Run&#8217; button on the bottom left like we did with the addition calculations.<\/p>\n<p>If &#8216;calculation result:1&#8217; is displayed, it is a success!<\/p>\n\n\n<h2 class=\"wp-block-heading\">Multiplication, Division<\/h2>\n\n\n<p>We follow the same steps for multiplication and division, but the symbols (operators) are different from what we are used to, so try to remember them.<\/p>\n<div class=\"simple-box4\">\n<p>\u25a0Operators for multiplication, division<\/p>\n<p>&nbsp; Multiplication\u30fb\u30fb\u30fb&#8217;*&#8217;<\/p>\n<p>&nbsp; Division\u30fb\u30fb\u30fb&#8217;\/&#8217;<\/p>\n<\/div>\n<p>Now, let&#8217;s make a program like the one shown below.<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\n\n \/\/ multiply\n $result = 3 * 2;\n echo 'multiplication calculation result\uff1a' . $result . ',';\n  \n \/\/ divide\n $result = 4 \/ 2;\n echo 'division calculation result\uff1a' . $result;\n<\/pre><\/div>\n\n<p>It is a success if you click the &#8216;Run&#8217; button and<\/p>\n<p>&#8216;multiplication calculation result:6,division calculation result:2&#8217;<\/p>\n<p>is displayed.<\/p>\n<p><div class=\"jin-iconbox green-iconbox\"><div class=\"jin-iconbox-icons\"><i class=\"jic jin-ifont-pencil jin-icons\"><\/i><\/div><div class=\"jin-iconbox-main green--border\"><\/p>\n<p><em>Don&#8217;t just stick to simple calculations, but try calculations which are more difficult, such as combining addition and multiplication.<\/em><\/p>\n<p><em>For example, what is the answer of 765 + 875 * 568 \u2013 23 \/ 54?<\/em><\/p>\n<p><em>A computer could give you the answer right away.<\/em><\/p>\n<p><\/div><\/div><\/p>\n\n\n<h2 class=\"wp-block-heading\">Final thoughts<\/h2>\n\n\n<p>Calculation processes are written in pretty much all programs of machines.<\/p>\n<p>We&#8217;ll be using them a lot in this lecture series, so please try to remember how to write them out.<\/p>\n<p>Also, this time we only put one value in a variable, but next time I will explain how you can put multiple values into one variable, so please look forward to it!<\/p>\n<p>See you next time!<\/p>\n\n\n<br>\n\n\n\n<div class=\"wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-1 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-button alignleft is-style-outline is-style-outline--e383d86f0440822f5d7e2b73be8fba2e\"><a class=\"wp-block-button__link has-vivid-cyan-blue-color has-text-color\" href=\"https:\/\/katblog.manadream.net\/index.php\/2020\/04\/22\/lets-display-letters\/\">&lt;&lt;Proceed to previous article<\/a><\/div>\n\n\n\n<p><\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-button alignright is-style-outline is-style-outline--e8c3b27033dfd8a9feb30853b37bc60c\"><a class=\"wp-block-button__link has-vivid-cyan-blue-color has-text-color\" href=\"https:\/\/katblog.manadream.net\/index.php\/2020\/05\/29\/what-are-array\/\">Proceed to next article&gt;&gt;<\/a><\/div>\n\n\n\n<p><\/p>\n<\/div>\n<\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello, I#8217;m kat, the manager of #8216;kat#8217;s blog. #8216;For the third installment of [Programming<\/p>\n","protected":false},"author":1,"featured_media":4083,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_locale":"ja","_original_post":"https:\/\/katblog.manadream.net\/?p=3582","_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[102],"tags":[107,108],"class_list":["post-3582","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programming-lessons","tag-english","tag-programming","ja"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/05\/calculate.png","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/paUgnN-VM","_links":{"self":[{"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/posts\/3582"}],"collection":[{"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/comments?post=3582"}],"version-history":[{"count":29,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/posts\/3582\/revisions"}],"predecessor-version":[{"id":4085,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/posts\/3582\/revisions\/4085"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/media\/4083"}],"wp:attachment":[{"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/media?parent=3582"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/categories?post=3582"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/tags?post=3582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}