{"id":73775,"date":"2023-11-17T14:24:46","date_gmt":"2023-11-17T12:24:46","guid":{"rendered":"https:\/\/codeacademy.bg\/uncategorized-bg\/strukturata-na-kompyutarna-programa\/"},"modified":"2024-04-08T20:08:05","modified_gmt":"2024-04-08T17:08:05","slug":"strukturata-na-kompyutarna-programa","status":"publish","type":"post","link":"https:\/\/codeacademy.bg\/en\/programirane\/strukturata-na-kompyutarna-programa\/","title":{"rendered":"Programming Fundamentals: The Structure of a Computer Program with Python Examples"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">For beginners, understanding the structure of a computer program can be a pivotal moment in learning the basics of programming. A computer program is a sequence of instructions executed by a computer to perform a specific task. This article will broadly explain the structure of a computer program and use the Python language to illustrate the main concepts.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">1: Understanding the Structure of a Computer Program<\/span><\/p>\n<p><span style=\"font-weight: 400;\">1.1. Input and Output<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Every computer program processes data that is provided as input and generates results as output. For example, a program might take two numbers as input and perform an operation to add them, then return the result. The input and output can vary depending on the program&#8217;s task.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">1.2. Sequence of Instructions<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Programs execute instructions sequentially, with each instruction following the previous one. This means that the order of instructions is important and determines how the program will execute. All instructions must be clearly defined and formatted so that the computer can understand and execute them correctly. Remember, the computer does exactly what we tell it to. If we haven&#8217;t given it clear instructions, it won&#8217;t perform the task.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">1.3. Conditions and Loops<\/span><\/p>\n<p><span style=\"font-weight: 400;\">To perform complex logical operations, programs use conditions and loops. Conditions are logical expressions that check whether a condition is true or false. For example, a program might check if one number is greater than another. Loops allow the program to execute certain instructions repeatedly, as long as a condition is met.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2: Structure of a Computer Program<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2.1. Program Sections<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Every computer program can be divided into several basic sections:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Including Libraries (import): Many programs require libraries or modules that provide additional functionalities. Libraries and modules are code written by other programmers that we can reuse when writing our programs. This is quite convenient, but we always need to be fully aware of what the pre-written code we&#8217;re using does. For example, in Python, we can use import to include libraries.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Input Data (input): This section typically contains code to receive input data from the user or other sources. In our Python example, we can use the input() function.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Processing (processing): Here is where the code that performs operations on the input data is located. This includes mathematical operations, logical checks, loops, and more.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Output (output): After processing the data, the program generates an output. This output can be displayed on the screen, written to a file, or sent to other devices.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2.2. Code Example<\/span><\/p>\n<p><span style=\"font-weight: 400;\">To understand the structure of a computer program, let&#8217;s consider a simple Python code example. Say we want to write a program that adds two numbers provided by the user and displays the result on the screen:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8220;`python<\/span><\/p>\n<p><span style=\"font-weight: 400;\"># Input<\/span><\/p>\n<p><span style=\"font-weight: 400;\">num1 = float(input(&#8220;Enter the first number: &#8220;))<\/span><\/p>\n<p><span style=\"font-weight: 400;\">num2 = float(input(&#8220;Enter the second number: &#8220;))<\/span><\/p>\n<p><span style=\"font-weight: 400;\"># Processing<\/span><\/p>\n<p><span style=\"font-weight: 400;\">sum = num1 + num2<\/span><\/p>\n<p><span style=\"font-weight: 400;\"># Output<\/span><\/p>\n<p><span style=\"font-weight: 400;\">print(&#8220;The sum of the numbers is:&#8221;, sum)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8220;`<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This code can be divided into sections as follows:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Including Libraries: In this case, there are no included libraries, but if there were, they would be at the top.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Input Data: Input data is received with input().<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Processing: In this case, processing is the addition of the numbers.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Output: The result is displayed on the screen with print().<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This elementary example illustrates the structure of a computer program and how the code within it is structured.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Understanding the structure of a computer program is fundamental for anyone starting in programming. As seen in the Python example, programs consist of a sequence of instructions that process input data and generate output. The structure of the program is divided into sections that perform specific tasks.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">I hope this article has helped you understand what the structure of a computer program is and how it is used in practice. With this foundational set of knowledge, you can move on to more complex programming tasks and develop your programming skills.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>For beginners, understanding the structure of a computer program can be a pivotal moment in learning the basics of programming. A computer program is a sequence of instructions executed by a computer to perform a specific task. This article will broadly explain the structure of a computer program and use the Python language to illustrate [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":73148,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"content-type":"","footnotes":""},"categories":[97,98],"tags":[],"class_list":["post-73775","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programirane","category-programirane-za-nachinaesthi","grve-entry-item","grve-blog-item"],"_links":{"self":[{"href":"https:\/\/codeacademy.bg\/en\/wp-json\/wp\/v2\/posts\/73775","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codeacademy.bg\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codeacademy.bg\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codeacademy.bg\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codeacademy.bg\/en\/wp-json\/wp\/v2\/comments?post=73775"}],"version-history":[{"count":1,"href":"https:\/\/codeacademy.bg\/en\/wp-json\/wp\/v2\/posts\/73775\/revisions"}],"predecessor-version":[{"id":73776,"href":"https:\/\/codeacademy.bg\/en\/wp-json\/wp\/v2\/posts\/73775\/revisions\/73776"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codeacademy.bg\/en\/wp-json\/wp\/v2\/media\/73148"}],"wp:attachment":[{"href":"https:\/\/codeacademy.bg\/en\/wp-json\/wp\/v2\/media?parent=73775"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codeacademy.bg\/en\/wp-json\/wp\/v2\/categories?post=73775"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codeacademy.bg\/en\/wp-json\/wp\/v2\/tags?post=73775"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}