diff --git a/docs/chapter-00-preface.md b/docs/chapter-00-preface.md deleted file mode 100755 index d577565..0000000 --- a/docs/chapter-00-preface.md +++ /dev/null @@ -1,263 +0,0 @@ -# Preface - -The book introduces readers to writing **programming code** at a beginner's level (basic coding skills), working the **development environment** (IDE), using **variables** and data, **operators** and **expressions**, working with the **console** (reading input data and printing output), usage of **conditional statements** (**`if`**, **`if-else`**, **`if-elif-else`**), **loops** (**`for`**, **`while`**) and working with **functions** (declaring and calling functions, passing parameters, and returning values). The book uses **Python** programming language and **PyCharm** development environment. The covered training material provides basic preparation for a deeper study of programming. - - - -
This book only gives you the first steps to programming. It covers very basic skills that you must develop for years, to reach a high enough level and start working as a programmer.
- -The book is also used as an unofficial **textbook for school-level programming courses in the high schools**, studying professions like "**Programmer**", "**Application Programmer**" and "**System Programmer**". - -## Who is This Book Intended for? - -This book is suitable for **complete beginners in programming**, who want to find out what programming is and learn the main constructions for writing programming code that is used in software development. The book provides a **solid basis** of practical skills that are used for further study in programming and software development. - -## Why Did We Choose The Python Language? - -For this book, we chose **Python**, because it is a **modern** language for high-level programming and at the same time it is easy to learn and suitable for **beginners**. As a use **Python** is **widespread**, with a well-developed ecosystem, numerous libraries, and technological frameworks, and therefore gives many **prospects** for development. **Python** combines the paradigms of procedural, functional, and object-oriented programming in a modern way with easy-to-use syntax. In the book, we'll use the **Python language** and the **PyCharm** development environment, which is available for free from JetBrains. - -As we will explain more about later, the programming language you start with does not make a significant difference in the process of learning to code, but you still need to choose one. For this book, we will focus specifically on Java. You can find the principles and concepts explained here illustrated with other programming languages like C#, JavaScript, and Python at https://softuni.org. - -## The Book in Other Programming Languages: Java, JavaScript, C#, C++ - -This programming book for complete beginners is available in several programming languages (or is in the process of being adapted for them): -* [Programming Basics with Java (English)](https://java-book.softuni.org) -* [Programming Basics with JavaScript (English)](https://js-book.softuni.org) -* [Programming Basics with C# (English)](https://csharp-book.softuni.org) -* [Programming Basics with Python (English)](https://python-book.softuni.org) -* [Programming Basics with JavaScript (Bulgarian)](https://js-book.softuni.bg) -* [Programming Basics with Python (Bulgarian)](https://python-book.softuni.bg) -* [Programming Basics with C# (Bulgarian)](https://csharp-book.softuni.bg) -* [Programming Basics with Java (Bulgarian)](https://java-book.softuni.bg) -* [Programming Basics with C++ (Bulgarian)](https://cpp-book.softuni.bg) - -If you prefer a different language, choose from the list above. - -## Programming is Learned by a Lot of Writing, Not Reading! - -If anyone thinks they're going to read a book and learn to program without writing a code and solve tasks hard, they're delusional. Programming is learned with **many, many practices**, with writing code every day and solving hundreds, even thousands of tasks, seriously and with perseverance, for years. - -You need to **solve a lot of problems**, to make mistakes, to fix them, search for solutions and information on the Internet, to try, to experiment, to find better solutions, get used to the code, syntax, programming language, development environment, error search and debugging of non-working code, task reasoning, algorithmic thinking, breaking down problems in steps and implementing every step, gaining experience and improving your skills every day, because learning to write code is just **the first step towards the profession of a software engineer**. You have a lot to learn! - -We advise the reader, as a minimum, **to try all the examples from the book**, to interact with them, to change and test them. Even more important than the examples **are the exercises** because they develop the practical skills of a developer. - -**Solve all the tasks in the book**, because programming is learned by practice! The tasks after each topic are carefully selected to cover in-depth the included learning -material. The purpose of solving all tasks from all the topics covered is to give **complete writing skills to a program code** at the beginners level (as is the purpose of this book). - - - -
Solve all the exercises in the book. Otherwise, you won't learn anything! Programming is learned by writing a lot of code and solving thousands of problems!
- - -# About Software University (SoftUni) - -[The Software University (SoftUni)](https://softuni.org/learn/?utm_source=Java&utm_medium=text&utm_campaign=free+programming+books) is **the largest training center for software engineers in South-Eastern Europe**. Tens of thousands of students pass through the university every year. SoftUni was founded in 2014 as a continuation of the hard work of [**Dr. Svetlin Nakov**](https://nakov.com) in training **skillful software engineering professionals** by a practical, contemporary and high-quality education that combines fundamental knowledge with modern software technologies and a lot of practice. - -## SoftUni: High-Quality Practical Tech Education - -The Software University provides **quality education**, **profession**, **job** and **diploma** for programmers, software engineers and IT professionals. SoftUni builds an extremely successful and strong **connection between education and industry** by collaborating with hundreds of software companies, provides job and internships of its students, creates quality professionals for the software industry, and directly responds to the needs of employers via the training process. Learn more at https://softuni.org. - -## The SoftUni Interactive Classroom - -SoftUni’s self-paced programs teach software developers worldwide in the innovative **Interactive Classroom** that combines **video lessons, coding sessions, examples, and exercises** in a single platform on the Web. - -Using the **SoftUni Interactive Platform**, you **write, execute and test code directly into the browser** and your exercise solutions are automatically evaluated by the integrated **Judge system**. If you have difficulties with an assignment, you can **get assistance** in multiple ways: with automated hints and guidelines or through SoftUni’s **help center**. Try it at https://softuni.org. - -This is how the **SoftUni Interactive Classroom** looks like: - -![](/assets/chapter-0-images/Interactive-Classroom-Video.PNG) - -![](/assets/chapter-0-images/Interactive-Classroom-Live-Coding-Exercise.PNG) - -## Video: SoftUni and SoftUni Judge - -Watch a video lesson about SoftUni and SoftUni Judge here: https://www.youtube.com/watch?v=IwLET8SDBE4. - -## The Automated Judge System - -**The SoftUni Judge system** \([https://judge.softuni.org](https://judge.softuni.org)\) is an automated Internet system for **checking the solutions of programming exercises via series of tests**. The submission and verification happen in **real time**: you submit the solution and within seconds you get an answer whether it is correct. You earn points for each task depending on your answer. For a completely right one, you get the maximum points for the problem. With a partially correct solution, you receive a fraction of the points. And with a completely wrong answer, you get 0 points. This how the **SoftUni Judge** looks like:![](/assets/chapter-0-images/Judge-System-Exercise.PNG) - -**All problems from the current book are available for testing in SoftUni Judge** and we strongly recommend testing them after you solve them to be sure you don't miss anything and that your solution works correctly according to the task requirements. - -Keep in mind some **specifics about SoftUni Judge**: - -* For each task the **Judge system keeps the best score you had**. Therefore, if you upload a solution with wrong code or lower score compared to the previous one, the system won't take away your points. -* The output of your program is **compared** by the system to a strictly expected result. Every **unnecessary symbol, missing comma or space** may lead to 0 points on a particular test. The **output** that the Judge system expects is **described in the requirements of every task** and **nothing else should be added**. -* **Example:** If the output requires to print a number \(ex. `25`\), do not display any descriptive messages such as `The result is: 25`, just print as it is required, i.e. only the number. - -The SoftUni Judge system is **available any time** via its website: [https://judge.softuni.org](https://judge.softuni.org). - - * Using the SoftUni system is **free** and it's not bound with the participation in SoftUni's courses. - -We are convinced that after sending a few tasks **you will like getting instant feedback** for your solutions and the Judge system will become your favorite assistant in your programming practice. - -# How to Become a Software Developer? - -Dear readers, probably many of you have the ambition to become programmers and develop software for a living, or work in the IT area. That's why we have prepared for you a **short guide on "How to become a programmer"**, so we can help you take the first steps towards this desired profession. - -You can become a programmer \(working in a software company\) after **at least 1-2 years of intensive training and coding every day**, solving thousands of programming tasks, development of several more serious practical projects and gaining a lot of experience with code writing and software development. You can't become a programmer for a month or two! The profession of software engineer requires **a lot of knowledge**, covered with **a lot of practice**. - -## Video: Become a Software Engineer – 4 Essential Skills - -Watch a video lesson about SoftUni and SoftUni Judge here: https://youtu.be/Ds5PD3UW57k. - -## The 4 Essential Skills of the Software Developers - -There are **4 main skill groups** where all programmers must have. Most of these skills are resistant in time and are not influenced by the development in specific technologies \(that are changing constantly\). These are the skills that **any good programmer** has and to which every beginner must strive: - -* **Coding **\(20%\) -* **Algorithmic thinking** \(30%\) -* **Computer science and software engineering concepts** \(25%\) -* **Languages and software technologies** \(25%\) - -## Skill \#1 – Coding \(20%\) - -**Writing code** forms around 20% of the minimum knowledge and skills of a programmer, needed for starting a job in a software company. The skill of coding includes the following components: - -* Working with variables, conditional statements, loops -* Using functions, methods, classes and objects -* Data manipulation: arrays, lists, hash tables, strings - -The skill of coding **can be acquired in a few months** of hard learning and solving practical problems by writing code every day. This book covers only the first point of coding: **working with variables, conditional statements and loops**. The rest remains to be learned in follow-up trainings, courses and books. - -The book \(and the courses based on it\) gives only the beginning of one long and serious training on the way to professional programming. If you don't learn perfectly the material from this book, you can't become a programmer. You are going to miss fundamentals and it will be harder in the future. For this reason, **give enough time to programming basics**: solve many problems and write code every day for months until you learn to **solve every problem from the book very easily**. Then go ahead. - -We specifically note that **the programming language does not matter** for the ability to code. You can code or not. If you can code with C\#, you will easily learn to code with Java, C++ or other languages. That's why **the coding skills** are being studied quite seriously at the in all [SoftUni software engineering programs](https://softuni.org), and each programming book for beginners starts with them, including this one. - -## Skill \#2 – Algorithmic Thinking \(30%\) - -The algorithmic \(logical, engineering, mathematical, abstract\) thinking forms around 30% of the minimum skills of a programmer needed to start the profession. **Algorithmic thinking** is the ability to break a particular problem into a logical sequence \(algorithm\), to find a solution for every separate step and then assemble the steps into a working solution. That is the most important skill of any programmer. - -How to **build algorithmic thinking**? - -* Algorithmic thinking is developed by solving **multiple programming \(1000+\) problems**, as diverse as possible. That is the recipe: solving thousands of practical problems, building algorithms and implementing the algorithms, along with debugging the issues that come up in the process. -* Sciences like physics, mathematics and similar ones helps a lot, but they are not mandatory! People with **engineering and technical skills** usually learn very easily to think logically, because they already **have problem solving skills**, even if it is not algorithmic. -* The ability of **solving programming problems** \(for which algorithmic thinking is needed\) is extremely important for a programmer. Many companies test particularly this skill during their job interviews. - -The current book develops the **beginner level of algorithmic thinking**, but it's not enough to make you a good programmer. To become good at this profession you must add **logical thinking and problem solving skills**, beyond the range of this book. For example, working with **data structures** \(arrays, lists, matrices, hash-tables, binary trees\) and basic **algorithms** \(searching, sorting, searching in tree structures, recursion, etc.\). - -**Algorithmic thinking skill** can be developed while studying in the [Software Developer programs](https://softuni.org) at SoftUni as well as in specialized algorithmic courses data structures and algorithms. - -As you may have guessed, the choice of **programming language does not matter** for the development of algorithmic thinking. It is a skill unrelated to Programming. Because of their well-developed logical thinking, there is the misconception that all programmers are smart people and having a high IQ is a requirement for entering into the profession. - -## Skill \#3 – Computer Science and Software Engineering Concepts \(25%\) - -**Fundamental knowledge and skills** for programming, software development, software engineering and computer science comprise around 25% of the developer's minimum skills to start a job. Here are the more important of these skills and knowledge: - -* **Basic mathematical concepts** related to programming: coordinate systems, vectors and matrices, discrete and non-discrete mathematical functions, state automata and state machines, combinatorics and statistics concepts, algorithm complexity, mathematical modeling and others -* **Programming skills** – code writing, working with data, using conditional statements and loops, working with arrays, lists and associative arrays, strings and text processing, working with streams and files, using programming interfaces \(APIs\), working with IDE, debugger, developer tools, etc. -* **Data structures and algorithms** – lists, trees, hash-tables, graphs, search, sorting, recursion, binary search trees, etc. -* **Object-oriented programming** \(OOP\) – working with classes, objects, inheritance, polymorphism, abstraction, interfaces, data encapsulation, exceptions management, design pattern -* **Functional programming** \(FP\) – working with lambda functions, higher order functions, functions that return a function as a result, closure, etc. -* **Databases** – relational and non-relational databases, database modeling \(tables and links between them\), SQL query language, object-relational mapping \(ORM\), transactions and transaction management -* **Network programming** – network protocols, network communication, TCP/IP, concepts, tools and technologies from computer networks -* **Client-server** interaction, peer to peer communication, back-end technologies, front-end technologies, MVC architectures -* **Technologies for server-side development** **\(back-end\) **– Web server architecture, HTTP protocol, MVC architecture, REST architecture, web development frameworks, templating engines -* **Front-end technologies \(client-side development\)** – HTML, CSS, JS, HTTP, DOM, AJAX, communication with back-end, calling REST API, front-end frameworks, basic design and UX \(user experience\) concepts -* **Mobile technologies** – mobile apps, Android and iOS development, mobile user interface \(UI\), calling server logic -* **Embedded systems** – microcontrollers, digital and analog input and output control, sensor access, peripheral management -* **Operating systems (OS)** – working with operating systems \(Linux, Windows, etc.\), installation, configuration and basic system administration, process management, memory, file system, users, multitasking, virtualization and containers -* **Parallel and asynchronous programming** – thread management, asynchronous tasks, promises, common resources, and access synchronization -* **Software engineering** – source control systems, development management, task planning and management, software development methodologies, software requirements and prototypes, software design, software architectures, software documentation -* **Software testing** – unit testing, test-driven development, QA engineering, error reporting and error tracking, automation testing, build processes and continuous integration - -We need to once again mention that **the programming language does not matter** for acquiring all these skills. You will accumulate them slowly, over years. Some fundamental knowledge can be learned theoretically, but to get an in-depth understanding of it you need a lot of practice. - -Fundamental knowledge and skills for programming, software development, software engineering, and computer science are taught during the [**Software Developer Program**](https://softuni.org), as well as a number of additional trainings. Working with a variety of software libraries, APIs, frameworks and software technologies and their interaction gradually builds this knowledge and skills, so do not expect that you will understand them from a single course, book or project. - -Having **basic knowledge in the areas listed above** is enough to start a job as a programmer. Your further improvement will come as a result of the technology and development tools you will use in your day-to-day work. - -## Skill \#4 – Programming Languages and Software Technologies \(25%\) - -**Programming languages and software development technologies** form around 25% of a programmer's skills. They have the largest learning content, but they change very fast over time. If we look at the **job offers** in the software industry, they usually mention words like the ones below, but in the job offers they secretly mention **the three main skills**: coding, algorithmic thinking and knowing the fundamentals of computer science and software engineering. - -For those clearly technological skills **the programming language does matter**. - -* **Note**: only for these 25% of the profession the programming language does matter! -* **For the rest 75% of the skills the programming language doesn't matter**, and these skills are resistant in time and transferable between different languages and technologies. - -Here are some commonly used software development stacks which software companies are looking for \(as of Jan 2019\): - - **C#** + OOP + FP + classes from .NET + SQL Server databases + Entity Framework (EF) + ASP.NET MVC + HTTP + HTML + CSS + JS + DOM + jQuery + cloud + containers - - **JavaScript (JS)** + OOP + FP + databases + MongoDB or MySQL + HTTP + web programming + HTML + CSS + JS + DOM + jQuery + Node.js + Express + Angular or React + cloud + containers - - **Python** + OOP + FP + databases + MongoDB or MySQL + HTTP + web development + HTML + CSS + JS + DOM + jQuery + Django or Flask + cloud + containers - - **Java** + Java API classes + OOP + FP + databases + MySQL + HTTP + web programming + HTML + CSS + JS + DOM + jQuery + JSP / Servlets + Spring MVC or Java EE / JSF + cloud + containers - - **PHP** + OOP + databases + MySQL + HTTP + web development + HTML + CSS + JS + DOM + jQuery + Laravel or Symfony or other MVC framework for PHP + cloud + containers - - **C++** + OOP + STL + Boost + native development + databases + HTTP + other languages and technologies - - **Swift** + OOP + MacOS + iOS + Cocoa + Cocoa Touch + XCode + HTTP + REST + other languages and technologies - - **Go** + OOP + Linux + Protobuf + gRPC + cloud + containers + other languages and technologies - -If the words above look scary and incomprehensible, then you are at the very beginning of your career and you need **many years of learning** until you reach the profession of a software engineer. Do not worry, every programmer goes through one or several technology stacks and needs to study **a set of interconnected technologies**, but it is imperative for you is know how to write **programming logic** (to code) and **think algorithmically** (to solve programming problems). Becoming a good software engineer is impossible without those skills! - -## The Programming Language Doesn't Matter! - -As it already became clear, **the difference between programming languages** and more specifically between the skills of developers in different languages and technologies forms around **10-20% of the skills**. - -* All programmers have around **80-90% of the same skills** that do not depend on the programming language! These are the skills to program and to design and develop software, that are very similar in different programming languages and development technologies. -* The more languages and technologies you know, the faster you will learn new ones, and the less you will feel the difference between them. - -Let us state once again that the **choice of programming language (mostly) does not matter** - you just need to learn to program. This process starts with **coding** (by reading this book or enrolling in a [**Software Developer program**](https://softuni.org), continues with mastering more complex **programming concepts** (like data structures, algorithms, OOP, and FP), and includes using **fundamental knowledge and skills for software development, software engineering, and computer science**. - -Only when you start working with a specific technology into a software project you will need **a specific programming language**, knowledge about specific programming libraries \(APIs\), frameworks and software technologies \(front-end UI technologies, back-end technologies, ORM technologies, etc.\). Keep calm, you will learn them, all programmers are learning them, but first you need to learn the foundation: **to program and do it well**. - -This book uses the C\# language, but it is not required and can be replaced with Java, JavaScript, Python, PHP, C++, Ruby, Swift, Go, Kotlin, or any other language. To be a **software developer**, you need to learn **coding** \(20%\), learn **algorithmic thinking**, and **solve problems** \(30%\), to have **fundamental knowledge of programming and computer science** \(25%\) and to master a **specific programming language and the technologies around it** \(25%\). Be patient, for a year or two all this can be mastered on a good starting level, if you are serious. - - -# The History Behind This Book - -The main engine and project manager for the creation of the current **free programming book for beginners** with open source is **[Svetlin Nakov, PhD](https://nakov.com)**. - -In 2014, the SoftUni initiative was launched. In the beginning, it had a wider reach and included more theory, but in 2016 Svetlin Nakov, PhD completely revised them, renovated, simplified, and **directed them to be more practical**. This is how the **learning content core of this book was created**. - -SoftUni's free programming start-up trainings are probably the largest ever conducted in Bulgaria. On the principle of free software and free knowledge, Svetlin Nakov led a **team of volunteers** and started this open-source project, initially to create a book based on programming with the C# language and later with other programming languages. - -## Author Team - -This book is developed by a broad author's team of **volunteers** who dedicated their time to give away the systematized knowledge and guide you at the start of programming. Below is a list of the main book authors (in alphabetical order): - -> **Boncho Vulkov, Hristo Minkov, Iliya Iliev, Martin Tsarev, Miglen Evlogiev, Milena Angelova, Mirela Damyanova, Nikolay Kostov, Petar Ivanov, Petya Gospodinova, Svetlin Nakov, Tanya Evtimova, Tanya Staneva, Teodor Kurtev, Ventsislav Petrov, Vladimir Damyanovski, Yordan Darakchiev** - -A large team of authors has a significant contribution to this book. Below is a list of the additional book contributors (editors, translators, others): - -> Aleksander Krastev, Aleksander Lazarov, Aleksander Peev, Aleksandra Stoycheva, Angel Dimitriev, Ariet Motzeva, Daniel Tsvetkov, Denis Milanov, Dimitar Dzhapunov, Dimitar Tatarski, Dimo Dimov, Diyan Tonchev, Dzhaner Hasan, Elena Rogleva, Hristiyan Hristov, Hristo Hristov, Iskra Nikolova, Ivelin Kirilov, Jordan Liubenov, Julieta Atanasova, Kalin Primov, Kaloyan Nenchev, Kristiyan Pamidov, Luboslav Lubenov, Martin Zhelev, Mihail Georgiev, Natali Dimitrova, Nikola Slavchev, Nikolay Bankin, Nikolay Dimov, Pavlin Petkov, Petar Ivanov, Rositsa Nenova, Ruslan Filipov, Simeon Stavrev, Stefka Vasileva, Svetlin Nakov, Teodor Kurtev, Tonyo Zhelev, Tsvetan Iliev, Vasko Viktorov, Venelin Bekyarov, Ventsislav Petrov, Yanitsa Vuleva, Yulian Linev, Zahariya Pehlivanova, Zhivko Nedyalkov. - -Book cover design: Marina Shiderova. - -The book is written in the period June-October 2018. - -## Official Website of The Book - -The current book on **The basics of Python programming for beginners** is available for free use on the Internet from: - -

https://python-book.softuni.org

- -This is **the official website of the book** and there will be uploaded its latest version. - -## License and Distribution - -The book is distributed **for free** in electronic format under an open license **[CC-BY-NC-SA](https://creativecommons.org/licenses/by-nc-sa/4.0/)**. - -**The source code** of the book can be found on GitHub: https://github.com/SoftUni/Programming-Basics-Book-Python-EN. - -International Standard Book Number (ISBN): **978-619-00-1403-4**. - -## The Book That Helps Teachers - -If you are a **teacher of programming**, informatics, or information technology or want **to teach programming**, this book gives you more -than a well-structured learning material with many examples and tasks. **Free of charge** with the book you receive **quality educational content** for teaching in school, in the **Bulgarian language**, by the school requirements: - -* **Educational presentations** (PowerPoint slides) for each learning topic tailored to 45-minute hours in schools – free of charge. -* Well-designed **tasks** for class and homework, with detailed conditions and sample entrance and exit – free of charge. -* **An automated task and homework verification system** (Online Judge System) to be used by students, also free of charge. -* **Video lessons** with methodological instructions from the free course for programming teachers, which is held regularly by the SoftUni Foundation. - -## Bug Reports - -If you find **bugs**, inaccuracies, or defects in the book, you can report them in the official tracker of the project: - -

https://github.com/SoftUni/Programming-Basics-Book-Python-EN/issues

- -We can't promise that we will edit everything you send us, but we are willing to constantly improve the quality of this book so that the reported errors and all reasonable suggestions will be addressed. - -## Enjoy Your Reading! - -And be sure **to write code** in large quantities, **try the examples** from each topic and, above all, **solve the tasks from the exercises**. You won't learn to program just by reading, so make sure you put time into solving exercises! diff --git a/docs/chapter-01-first-steps-in-programming.md b/docs/chapter-01-first-steps-in-programming.md deleted file mode 100755 index 2f60fbb..0000000 --- a/docs/chapter-01-first-steps-in-programming.md +++ /dev/null @@ -1,591 +0,0 @@ -# Chapter 1. First Steps in Programming -In this chapter, we are going to find out **what programming** is at its core. We are going to become familiar with the idea of **programming languages** and explore the environments for software development (**Integrated Development Environment** – IDEs); we'll see how to work with them, in particular with **PyCharm**. We will write and execute our **first program** written in the programming language Python and then we're going to practice with a few tasks: we will create a console-based program, a graphical application, and a Web application. We will learn how to use **SoftUni's Judge System** to check the correctness of our solutions to the problems in this book. Finally, we'll look at some typical mistakes made during code writing and we're going to learn how to avoid them. - -## What Does 'To Program' Mean? - -To program means to give instructions to the computer, for example, *play a certain sound*, *print something on the screen*, or *multiply two numbers*. When there's a series of commands, we have a computer program (script). The computer program's text is called **program code** (**source code** or **just code**). - -## Computer Programs - -**Computer programs** represent a **series of commands** written in a particular **programming language**, like Python, C#, Java, JavaScript, Ruby, PHP, C, C++, Go, etc. To write commands, we need to be familiar with the **syntax and semantics of the language** we'll be using, in our case – **Python**. In this book, we're going to cover programming in general, as well as Python's particular syntax and semantics. We will examine each step of writing code, starting with the simplest and eventually reaching more complex programming constructs. - -### Algorithms - -Computer programs usually execute some sort of algorithm. **Algorithms** are a series of steps used to complete a task and achieve an expected result - something like a recipe. For example, if we need to fry some eggs, we follow a certain recipe (algorithm): we heat some oil in a pan, then we break the eggs, we wait until they're cooked, and finally, move the pan away from the heat. Similarly, in programming, **computer programs execute algorithms** – a series of commands needed to complete a certain task. If we want to print a series of numbers in ascending order, for example, we need an algorithm. It will go through all the numbers, find the smallest one and print it, then go through the rest of them and do the same until there are no more numbers left. -To create programs, write program code (commands), execute it and other operations that have to do with making programming more convenient, we need a **development environment** (IDE) like **PyCharm**. - -### Programming Languages, Compilers, Interpreters and Development Environments -**Programming languages** are artificial languages (syntax for expression), designed to **issue commands** which we expect the computer to read, process and execute. With the help of programming languages, we write a series of commands (**programs**) that **tell the computer what to do**. Execution of computer programs can be achieved by using either a **compiler** or an **interpreter**. - -**The compiler** translates code from a programming language into **machine code** and for each construct (command) in the code, it chooses an appropriate, predefined fragment of machine code while simultaneously checking the program's text for **errors**. Together, all the compiled fragments represent the original program translated in machine code, exactly how the computer's microprocessor is expecting it. After it's been compiled, the program can be directly executed by the microprocessor in cooperation with the operating system. Compiled programming languages **compile the program** before executing it and find syntactic errors (incorrect commands) during compile time. Languages like C++, C#, Java, Swift and Go work with compilers. - -Some programming languages don't use a compiler but are **directly interpreted** by specialized software called an interpreter. **The interpreter** is a **program that executes programs**, written in some programming language. It executes the program's commands in sequence and understands not only single commands and series of commands but also other language constructs (checks, iterations, functions, etc.). PHP, Python and JavaScript are languages that work with an interpreter and are executed without the need to be compiled. Due to lack of preliminary compilation, interpreted languages' errors are found during run time, after the program has already started working. - -Overall, compiled languages work slower than their interpreted counterparts. The difference in execution speed is sometimes insignificant, but in other cases massive. In interpreted programming languages we can change code quicker and re-execute (to remove a mistake, for example), while compiled languages are slower after a code change has been introduced, due to the need for compilation. - -**The development environment** (Integrated Development Environment – **IDE**) combines traditional instruments for software development. In the development environment we write code, compile and execute programs. Development environments incorporate a text editor for writing code, a **programming language**, **a compiler or interpreter**, an **execution environment** where our program is executed, a **debugger** that traces our program and looks for errors, **instruments for design and user interface** as well as other instruments and add-ons. - -**Development environments** are convenient because they incorporate everything necessary to develop a program, so there's no need to leave the environment. If we don't use a development environment, we'll have to write code in a text editor, compile it with a command from the console, execute it with another command from the console and write additional commands, when needed, which would cost a lot of time. This is why most programmers use IDEs for everyday work. - -Programming with **Python** is usually done in the development environment **PyCharm** which is developed and distributed by JetBrains. You can download it from: [https://www.jetbrains.com/pycharm](https://www.jetbrains.com/pycharm). -Here's what the PyCharm environment looks like in action: - -![](/assets/chapter-1-images/PyCharm-IDE-in-action.png) - -Alternatives to PyCharm for writing code in Python are **Visual Studio Code** (https://code.visualstudio.com), **Atom** (https://atom.io), **Eclipse for Python** (https://www.eclipse.org) together with the add-on **PyDev** (https://pydev.org) and others. In this book, we'll use the development environment PyCharm. - -Alternatives to desktop development environments (IDE) are online environments for Python programing such as [**Repl.it**](https://repl.it/languages/python3) and [**PythonAnywhere**](https://www.pythonanywhere.com). They're great for testing short examples, when we cannot install an IDE locally, or when we want to easily share our code with colleagues. Here's an example of how to execute **Python code** in **Repl.it**: - -![](/assets/chapter-1-images/Python-code-in-Repl.it.png) - -### Low-Level, High-Level Languages and Runtime Environments - -A program is, in essence, a **set of instructions** that ask the computer to carry out certain tasks. They are entered by the programmer and **executed unconditionally by the machine**. - -There are different types of **programming languages**. **Lowest-level** languages can be used to write the very **instructions commanding the processor** - **Assembler** is one such language. Higher-level languages can be utilized to create an operating system, drivers for managing hardware (video card drivers, for example), web browsers, compilers, engines for game graphics (game engines) and other system components and programs. Even higher-level languages like **JavaScript**, **C#** and **Python** are used to create application software, like programs for reading mail or chatting. - -**Low-level languages** command hardware directly and require a lot of effort and a vast number of commands, to carry out a certain task. **Higher-level languages** require less code to achieve the same result, but have no direct access to hardware. They are used to develop application software like web and mobile applications. - -Most of the software we use daily like music players, video players, GSP programs, etc. is written on high-level **languages for application programming** like Python, JavaScript, C#, Java, C++, PHP, etc. - -**Python is an interpreted language** which means we write commands and they're executed immediately after running the program. As a result of that, we will realize we've made a mistake in our code only after we've started our program and reached the incorrect command. In cases like these, **IDEs** like PyCharm are extremely helpful as they check our code while we're writing it and alarm us of potential issues. After we've written our code and want to test it, we can save it in a file with extension **`.py`**. - -## Python Interpreter: Installation and Use - -To program in Python, we first need to **install a Python interpreter**. It executes commands and runs programs, written in Python, and is essential if we want to use Python on our computer. - -### Installing The Python Interpreter - -Installing Python is quite simple. Just go to https://python.org/downloads and download the latest version for your platform. - -![](/assets/chapter-1-images/Python-download.png) - -On **Windows**, the installation is a straightforward process of clicking **[Next]**, **[Next]** and **[Finish]**. On **Linux**, you need to use a package installer like `sudo apt-get install python3`. - - - -
Use Python version 3.x or newer. Python 2 is outdated technology and although it's accessible by default on many systems, it's problematic and many of the examples in this book won't work on it.
- -## Starting The Python Interpreter - -After the Python interpreter has been installed, we can **get it started** and have a tinker at it. If your environment is Windows, use the **[Start]** menu and find the application you just installed – 'Python 3.7 (64-bit)', for instance. On a Linux / MacOS environment, write the command `python3` in the console. Here's what the Python interpreter should look like on Windows: - -![](/assets/chapter-1-images/Python-3.7-Shell.png) - -### Working with The Python Interpreter - -Python is an **interpreter** and it can be used in **command mode**: we write a **command**, it's executed and we receive the **result**. The simplest command we can use is to make Python calculate a numeric expression – `2 + 3`, for example: - -![](/assets/chapter-1-images/Python-shell-calculate-2-plus-3.png) - -As we can see, the answer is correct: `5`. -Let's try a few more commands: store the value `5` in a variable named `a` and print the result of `2 * a`: - -![](/assets/chapter-1-images/Python-shell-calculate-2-multiplied-by-a.png) - -**Play around** with the Python interpreter yourself. Try calculating **1234567890 * 234567890 * 34567890**. Did it work? Try using an **incorrect command** (write your name, for example). Try calculating `2 ** 20` and guessing what that might be. Have a go at printing the text *"Hello Python, how are you?"* using the command `print("some text")`. Is it working? - -## Computer Programs - -As we already mentioned, a program is a **series of commands**, in other words, it describes a series of calculations, checks, iterations and numerous other operations, which aim at producing a result. -The program is written in text format and the text is called **source code**. It's saved in a file with extension `.py` (`main.py`, for instance), and then it can be executed through your browser or the **console** with the help of **Python Shell**. In **script and interpreted languages**, like JavaScript, Python and PHP, the source code is executed step by step by an interpreter. - -### Problem: A Program That Prints 'Hello' - -Let's start with a very basic example of a short **Python program**. It will print the word *"Hello"* like so: -```py -print("Hello") -``` - -We can execute it by typing in the Python interpreter: -![](/assets/chapter-1-images/Python-shell-print-Hello.png) - -### Problem: A Program That Plays The Music Tone 'A' - -Our next program will consist of a single **Python command** which plays the music tone 'A' (432 hertz) for half a second (500 milliseconds): -```python -import winsound - -winsound.Beep(432, 500) -``` -In a Windows environment we will **hear a sound**. Make sure your speakers aren't muted. On Linux and MacOs, the example won't work. - -### Problem: A Program That Plays a Series of Music Tones: -We can make our last program a bit more complex by creating a loop that passes a series of notes with increasing height to the command: -```python -import winsound - -for i in range(200, 4000, 200): - winsound.Beep(i, 300) -``` -In the example above we make the computer play very briefly (300 milliseconds) each subsequent tone with height 200, 400, 600, etc. hertz until reaching 4000 hertz. The result is something similar to a melody. -We will learn how iterations (loops) in programming work in **chapter** "[Loops](chapter-05-loops.md)", but for now, let's assume that they just repeat a command many times. - -### Problem: Program That Converts Levs (BGN - Bulgaria's currency) , into Euros - -Let's have a look at another simple program that reads a number of levs(BGN) from the user, converts them into euro (divides them by the euro exchange rate) and prints the result. This is a program of **three consecutive commands**. Enter and execute them in sequence: -```python -leva = int(input()) -euro = leva / 1.95583 -print(euro) -``` - -Here's what the **result** of the above series of commands might look like: - -![](/assets/chapter-1-images/Python-shell-leva-to-euro.png) - -We looked at **three examples of computer programs**: single command, series of commands in a loop and a sequence of three commands. Let's now move on to the more exciting bit: writing our programs in **Python** and executing them. - -## How Can We Write a Console Program? - -Let's go through the necessary steps to **create and execute a computer program** that uses a text console (window for entering and printing text) to read and write its data. Such programs are called **console programs**. But first of all, we need to **install and prepare the development environment** where we will write and execute the Python programs from this book and the exercises that go along with it. - -## Development Environment (IDE) -As previously mentioned, we need a **development environment** (IDE) to program. The IDE is a program editor, where we write program code and execute it, discover our mistakes, correct them and start the program again. -- For programming in Python, we use the **PyCharm** environment, suitable Windows, Linux and MacOS operating systems. -- If we are programming in Java we might use **IntelliJ IDEA**, **Eclipse** and **NetBeans**. -- If we are programming in C# we might use **Visual Studio**. - -### Installing PyCharm Community -Let's start by installing the **PyCharm Community** integrated environment (in our example we'll be using version 2018, current as at October 2018). -The Community version of PyCharm is freely distributed by JetBrains and can be downloaded from: [https://www.jetbrains.com/pycharm/download](https://www.jetbrains.com/pycharm/download). - -The installation is typical for Windows - simply use the **[Next]** and **[Finish]** buttons. There's a Linux version available as well. -In the following paragraphs, we've described in detail **every step of the PyCharm Community 2018 installation process**. After we download the installation file and run it, we're greeted with the following screen: - -![](/assets/chapter-1-images/00.PyCharm-01.png) - -We hit **[Next]**, which takes us to the screen you see below: - -![](/assets/chapter-1-images/00.PyCharm-02.png) - -A window with PyCharm's installation panel is loaded: - -![](/assets/chapter-1-images/00.PyCharm-03.png) - -We tick the box which allows us to choose a shortcut depending on our operating system [**.py**] and [**Download and install JRE x86 by JetBrains**], and then click [**Next**]: - -![](/assets/chapter-1-images/00.PyCharm-04.png) - -Then we hit the **[Install]** button. - -![](/assets/chapter-1-images/00.PyCharm-05.png) - -After PyCharm installs, we'll see an information screen, where we can tick a box that says **[Run PyCharm]** which is going to start our IDE. After **PyCharm has started**, a screen similar to the one below will be displayed: - -![](/assets/chapter-1-images/01.Hello-python-01.png) - -That's it. We're ready to start working with PyCharm. - -### Older Versions of PyCharm - -We could also use older versions of PyCharm (version 2016 or 2012, for example) but it's **not recommended** since they don't have the newest capabilities for development and not all the examples in this book will run on them. - -### Online Development Environments - -There are also **alternative environments to develop online**, directly in your web browser. They aren't very easy to use but if you have no other option, you can start your education with them and install PyCharm later. Here are some links: -- Tutorials Point allows writing and executing code online: -[https://www.tutorialspoint.com/online_python_ide.php](https://www.tutorialspoint.com/online_python_ide.php). -- Another useful online development environment for writing and executing Python code is Repl.it: [https://repl.it/languages/python3](https://repl.it/languages/python3). - -### Projects in PyCharm - -Before we start working with PyCharm, let's get familiar with the term **PyCharm Project** - it represents the project we're currently working on. - -In the beginning that will be a console program which we'll learn how to write with the help of this book. After some more thorough studying and with time and practice, these projects will turn into applications, web apps and other projects. The PyCharm project uses **logic to group the numerous files** that make up a certain application or component. - -A single **Python project** consists of several **Python source files** (**.py**), configuration files and other resources. Every Python source file can have one or more **classes** and **functions**. **Classes** contain **functions**(actions), which are comprised of a **series of commands**. It may seem complicated, but in larger projects, this structure is extremely convenient and allows for the good organization of our work files. - -# Problem: Creating a Console Program 'Hello Python' - -Let's get back to our console program. Now that we have PyCharm installed, we can start it. Then we will create a new project: **[Create New Project]**. - -![](/assets/chapter-1-images/01.Hello-python-01.png) - -We will give our project a **meaningful name**, such as `FirstStepsInProgramming`: - -![](/assets/chapter-1-images/01.Hello-python-02.png) - -PyCharm will create an **empty project** for us and we can add Python files to it. We'll add a new Python file - **[File]** or right-click on our project -> **[New]** -> **[Python File]** and give it a meaningful name like `HelloPython.py`. - -We can adjust the version and location of the Python interpreter, which we're going to be using. We must have a Python interpreter, otherwise, we won't be able to execute the programs we've written. It's possible to have more than one version of Python on the same computer but for ease of use, in the beginning, **just install the latest version and use that**. If you haven't already installed Python, please do so before you continue. - -### Writing Program Code - -Writing Python code requires no additional preparation – creating a file with the `.py` extension is all we need. So let's directly proceed with writing our first line of code. We will write the following command: -```python -print('Hello Python') -``` -Here's what our program might look like in PyCharm: - -![](/assets/chapter-1-images/01.Hello-python-03.png) - -The `print('Hello Python')` command allows us to print the text message `Hello Python` on the console. The message needs to be surrounded with quotes, signifying text. - -This command is quite typical for programming: we call the function `print(...)` and pass the text literal `'Hello Python'` as its parameter. - -### Starting The Program - -To start the program we need to press **[Ctrl + Shift + F10]** or right-click – **[Run]**. If there are no errors, the program will execute. The result will be displayed on the console: - -![](/assets/chapter-1-images/01.Hello-python-04.png) - -The output from the program is the following text message: -```python -Hello Python -``` -The **'Process finished with exit code 0'** message is displayed at the end of the PyCharm console after the program has been executed, to signify that the program has finished with no errors. - -### Testing in The Judge System - -Testing the solutions to the problems in this book is completely automated via the **Judge System**'s website: [https://judge.softuni.org](https://judge.softuni.org). The solutions are judged immediately by the system. Each solution goes through a series of tests that are hidden; every test that passes grants the user certain points. - -The program we just wrote can be tested here: [https://judge.softuni.org/Contests/Practice/Index/1046#0](https://judge.softuni.org/Contests/Practice/Index/1046#0). To do that, simply paste the entire source code in the black field and choose **Python code** as is shown below: - -![](/assets/chapter-1-images/01.Hello-python-05.png) - -Then we need to send our solution by clicking the **[Submit]** button. The system returns a result in a few seconds which is displayed in the table of submitted solutions. If necessary, we can hit the 'Refresh' button at the upper right-hand corner of the table of submitted solutions: - -![](/assets/chapter-1-images/01.Hello-python-06.png) - -In the table, the Judge System will display one of the following **possible results**: -- A number of points (between 0 and 100), when the submitted code is compiled successfully (there are no syntactic errors) and can be tested. -- If our solution is **completely correct**, all tests are marked in green and we receive **100 points**. -- If our solution is **incorrect**, some tests are marked in red and we receive less than 100 or 0 points. -- If there are syntactic errors in our program, we receive a **compile-time error message**. - -### Test Your Tone-Playing Programs - -Now that you've learned how to **execute programs**, you can test the sample note-playing programs you have above. Have fun with them, try out different things. Try changing them and playing with them. Swap the `print('Hello Python')` command with `windsound.Beep(432, 500)` and add `import windsound` at the top, then start your program. Check whether your computer sound is on and turned up. If you're using an online development environment, you won't hear anything, because the program isn't executed on your computer, but somewhere else. The `windsound` Module may not work with some operating systems like Linux and MacOS. - -## Typical Mistakes in Python Programs - -One of the usual mistakes beginners make is mixing up **capital and lowercase letters**. However, they matter when we call commands and can impede proper functioning. Here's an example of such a mistake: -```python -Print('Hello Python') -``` - -In the example above, `print` is written incorrectly and the capital letter needs to be changed to lowercase. - -
In Python we don't use a semicolon (;) at the end of each command. Commands are separated by a new line or by indentation.
- -A missing **quotation mark** or **closing bracket** can also cause issues – the program will either **function improperly** or **not execute at all**. Such mistakes are hard to notice, especially with larger amounts of code. Here's an example: -```python -print('Hello Python) -``` - -This program will return an **error** and the code will be underlined to draw the programmer's attention to the missed closing bracket. - - ![](/assets/chapter-1-images/01.Hello-python-07.png) - -## What Have We Learned from This Chapter? - -First of all, we learned **what programming is** – **issuing commands written in a programming language** that the machine can understand and carry out. We also found out what a **computer program** is – a **series of commands** that aim to achieve a certain result. We gained some basic knowledge of the **Python programming language** and learned **how to create simple console programs** using PyCharm. Then we examined **Python's program code structure**. We looked at printing with the function **`print(...)`** and starting the program with **[Ctrl + Shift + F10]**. And last but not least, we now know how to test our code in **SoftUni's Judge System**. - -Top work! Let's now tackle the **exercises**. You do remember that learning how to program involves a lot of code writing and problem-solving, right? Let's do just that and put what we've learned into practice. - -## First Steps in Programming – Problems - -Welcome to the exercises. We are now going to write a couple of console applications, which will help us take a few more steps into programming. After that we will show you how to program something more complex – programs with a graphical and web user interface. - -### Problem: Expression - -Write a console-based **Python** program that **calculates** and **prints** the value of the following numerical expression: -

(3522 + 52353) * 23 - (2336 * 501 + 23432 - 6743) * 3

-Note: you are **not allowed to previously calculate the value** (for example with Windows Calculator). - -### Hints and Guidelines - -Create a new Python file and name it **Expression**. Then we need to **write the code** which will calculate the numeric expression above and print its value on the console. Pass the expression to the **`print(...)`** command by writing it within its brackets: - -![](/assets/chapter-1-images/02.Expression-01.png) - -Start the program with **[Ctrl + Shift + F10]** and check whether the result matches the one from the picture: - -![](/assets/chapter-1-images/02.Expression-02.png) - -### Testing in The Judge System - -Test your solution here: [https://judge.softuni.org/Contests/Practice/Index/1046#1](https://judge.softuni.org/Contests/Practice/Index/1046#1). -![](/assets/chapter-1-images/02.Expression-03.png) - -### Problem: Numbers from 1 to 20 - -Write a **Python console program** that **prints the numbers from 1 to 20** on separate lines on the console. - -### Hints and Guidelines - -Create a Python file and name it **`nums_1_to_20.py`**: - -![](/assets/chapter-1-images/03.Numbers-1-to-20-01.png) - -Inside the file write 20 **`print()`** commands, each on a separate line, to print the numbers from 1 to 20 one after another. Some of you may be wondering if there is a more clever way. Don't worry, there is, but we will mention it later on. - -![](/assets/chapter-1-images/03.Numbers-1-to-20-02.png) - -Let's now **start the program** and check whether the result is what we're expecting: -``` -1 -2 -… -20 -``` - -### Testing in The Judge System - -Test your solution here: -[https://judge.softuni.org/Contests/Practice/Index/1046#2](https://judge.softuni.org/Contests/Practice/Index/1046#2). -Now try and **think of a more clever way** we can write this program, to avoid repeating the same command so many times. Look up information for "[for loop Python](https://www.google.com/search?q=for+loop+python)" on the Internet. - -### Problem: Triangle of 55 Stars - -Write a **Python console program** that prints a **triangle of 55 stars** on 10 lines: -``` -* -** -*** -**** -***** -****** -******* -******** -********* -********** -``` - -### Hints and Guidelines - -Create a **new Python file** and name it **`triangle_of_55_stars.py`**. Inside we need to write code that prints our triangle, using 10 print() commands, like this: -```python -print('*') -print('**') -… -``` - -### Testing in The Judge System - -Test your solution here: -[https://judge.softuni.org/Contests/Practice/Index/1046#3](https://judge.softuni.org/Contests/Practice/Index/1046#3). - -Try and **improve your solution** to avoid repeating the same command so many times. Can this be achieved with a **`for`**-loop? Did you manage to invent a better solution (with a for-loop, for example) to the previous problem? The current problem can be solved with a similar, but a little more complex approach (a loop within another loop). It's completely fine if you can't figure it out, you'll remember this problem when we learn about loops in a few chapters. - -### Problem: Rectangle Area - -Write a **Python program** that **receives two numbers a and b, then calculates and prints** the area of a rectangle with sides **a** and **b**. - -### Sample Input and Output -| a | b | area | -| :---: | :---: | :---: | -| 2 | 7 | 14 | -| 7 | 8 | 56 | -| 12 | 5 | 60 | - -### Hints and Guidelines - -Create a **new Python file**. We'll use the following commands to read our numbers: - -![](/assets/chapter-1-images/05.Rectangle-area-01.png) - -What's left is to finish the program so it can calculate the rectangle's area and print it. Pass the product of **`a`** and **`b`** to the already familiar **`print(...)`** command. In programming, we multiply using the **`*`** operator. - -### Test Your Solution - -Test your solution with a few examples. You should receive a result identical to the one you see below (we enter 2 and 7 as input and the program prints 14 – their product, as output): -``` -2 -7 -14 -``` - -### Testing in The Judge System - -Test your solution here: -[https://judge.softuni.org/Contests/Practice/Index/1046#4](https://judge.softuni.org/Contests/Practice/Index/1046#4). - -### Problem: Square of Stars - -Write a **Python console program that reads an integer positive number N** from the console and **prints a square of N stars** on the console, like in the examples below. - -### Sample Input and Output - -| Input | Output | Input | Output | Input | Output | -|-----|-----------|-----|-----------|-----|----------| -| 3 | \*\*\*
\* \*
\*\*\*| 4 |\*\*\*\*
\*  \*
\*  \*
\*\*\*\*| 5 |\*\*\*\*\*
\*   \*
\*   \*
\*   \*
\*\*\*\*\*| - -### Hints and Guidelines - -Create a **new Python file**. To read the number N (2 ≤ N ≤100), we use the following code: - -![](/assets/chapter-1-images/06.Square-of-stars-01.png) - -Finish the program so that it prints a square made up of stars. You may need to use **`for`**-loops. - -**Caution**: this task is more difficult than the rest and is presented to you at this point purposefully. It's marked with a star, to provoke you **to look for information on the Internet**. This is one of the most important skills you have to develop while you're learning to program. This is what you'll be doing every day if you work as a developer, so don't be scared, try it out. If you're having difficulties, you can also ask for help in the **SoftUni's Reddit Community**: [https://www.reddit.com/r/softuni/](https://www.reddit.com/r/softuni/). - -### Testing in The Judge System - -Test your solution here:[https://judge.softuni.org/Contests/Practice/Index/1046#5](https://judge.softuni.org/Contests/Practice/Index/1046#5). - -## Console, Graphical and Web Applications - -With **console applications**, as you've already noticed, **all operations** for reading input and printing output are done on the console. The input data is **entered on the console** and then it is read by the application; the console is also used to **print the output data** after or during the runtime of the program. - -While a console application **uses the text console**, web applications use a **web-based user interface**. **To execute them**, two things are needed – a **web server** and a **web browser**. The **browser** plays the main role in the **visualization of data and interaction with the user**. Web applications are much more pleasant for the user, they look better, and a mouse and touch screen can be used (for tablets and smartphones). Programming stands under all of that, of course. This is why **we need to learn how to program** and we have already made our first tiny steps towards achieving that. - -Graphical (GUI) applications have a **visual user interface**, directly on your computer or mobile device, without a web browser. Graphical applications (also known as desktop applications) contain one or more graphical windows where certain controllers are located (text fields, buttons, pictures, tables and others), which **allow dialog** with the user to be more intuitive. Similar to them are mobile applications on your smartphone or tablet: we use forms, text fields, buttons and other controls and we manage them with program code. This is why we learn to write code now: **code is everywhere in software development**. - -## Problem: Graphical and Web Applications - -We will now build a **basic web application** and after that, a simple **graphical application**, to have a look at what we will be able to create once we progress with programming and software development. We are not going to examine the techniques and constructions used in much detail. Rather, we are just going to have a peek at the arrangement and functionality of what we've created. After we progress with our knowledge, we will be able to develop bigger and more complex software applications and systems. We hope that the examples given below will boost your interest, rather than make you give up. - -## Graphical Application: 'Numbers Summator' - -Write a **graphical (GUI) application** that **calculates the sum of two numbers**. After the numbers are entered in the first text fields, and the button **[Calculate]** is clicked, calculate their sum and display the result in the third text field colored in green: - -![](/assets/chapter-1-images/07.Numbers-sum-01.png) - -We'll use the standard Python graphical library **TKInter** for our application (https://wiki.python.org/moin/TkInter. It enables us to create **graphical (GUI) applications** using the **Python** programming language. - -## Empty Python Project - -Create a **new Python project** named **"Summator-GUI"** in PyCharm: - -![](/assets/chapter-1-images/07.Numbers-sum-02.png) - -Add a new Python file named **summator.py** to the project. Then add **tkinter** as well: - -![](/assets/chapter-1-images/07.Numbers-sum-03.png) - -#### Creating The Basis for The GUI Project - -Next, we need to write the code for our graphical application, starting with the basis: - -![](/assets/chapter-1-images/07.Numbers-sum-04.png) - -We'll need the following components (controls): -* **Entry** – will enter the numbers that need to be calculated. -* **Label** – will serve to statically display text and the result of the calculation. -* **Button** – will calculate the sum of our numbers. - -![](/assets/chapter-1-images/07.Numbers-sum-05.png) - -Let's **initialize and visualize** our controls (widgets): - -![](/assets/chapter-1-images/07.Numbers-sum-06.png) - -And try to start our application with **[Ctrl + Shift + F10]** or right-click + **[Run]**. It should start but **not function correctly**, because we haven't specified what happens when the button is clicked: - -![](/assets/chapter-1-images/07.Numbers-sum-07.png) - -#### Application Logic - -Now we're going to write the code responsible for summing our numbers and displaying the result in the third field. For that to work, we add the **`calculate`** command upon the button's initialization: - -![](/assets/chapter-1-images/07.Numbers-sum-08.png) - -Then we write the **`calculate`** function's code: - -![](/assets/chapter-1-images/07.Numbers-sum-09.png) - -This code **takes the first number** from the **`firstNumberEntry`** field and stores it in the **`first_value`** **variable**. Then it stores the **second number** from the **`secondNumberEntry`** field in the **`second_value`** variable. It **sums** **`first_value`** and **`second_value`** and stores the result in the **`result`** variable. Finally, it **displays the text representation** of the **`result`** variable in the **`resultLabel`** field. - -Let's start the program again using **[Ctrl + Shift + F10]** or right-click + **[Run]** and check whether it's working correctly. Try and calculate **4** + **5**, then **-2.5** + **1.5**: - -![](/assets/chapter-1-images/07.Numbers-sum-10.png) ![](/assets/chapter-1-images/07.Numbers-sum-11.png) - -#### Managing Invalid Numbers - -Entering **invalid numbers** like **'a'** and **'b'** seems to create issues: - -![](/assets/chapter-1-images/07.Numbers-sum-12.png) - -This is due to the **conversion of the information entered in our text field into a number**. If the **value in the field isn't a number, our program returns an error**. We can fix the code to resolve this issue: - -![](/assets/chapter-1-images/07.Numbers-sum-13.png) - -The code you see above **intercepts number-handling errors** (catches exceptions) and in case of an error, **returns a `Not number/s`** value in the result field. If we start our program once more and enter an improper value, the **result is `Not number/s`** and our program continues working as intended: - -![](/assets/chapter-1-images/07.Numbers-sum-14.png) ![](/assets/chapter-1-images/07.Numbers-sum-15.png) - -Does that seem complicated? If it does, that's completely normal. We are at the very start of our programming journey. The example above requires much more knowledge and skills, which we are going to develop using this book and later on as well. Just allow yourself to have some fun with desktop programming. Or bravely move forward to the next example or the next chapter in the book. There will come a time when this becomes easy for you, but you have to put in some effort and be persistent. Learning programming is a slow process involving lots and **lots of practice**. - -### Web Application: 'Numbers Summator' -Now we are going to create something even more complex, but also more interesting: a Web application that **calculates the sum of two numbers**. By entering two numbers in the first two text fields and clicking the **[Calculate]** button, **their sum is calculated** and the result is displayed in the third text field. - -Keep in mind that we are creating a **Web-based application**. This is an application that is accessible through a web browser, just like your favorite email or news website. The web application is going to have a server-side (back-end), which is written in the Python language with **Flask** ([https://flask.palletsprojects.com](https://flask.palletsprojects.com)) technology, and a client-side (front-end), which is written in the **HTML** language (this is a language for visualization of information in a web browser). The Web application is expected to resemble the following: - -![](/assets/chapter-1-images/08.Numbers-sum-web-01.png) - -As opposed to console applications that read and write data in the form of text on the console, Web applications have a **Web-based user interface**. Web applications are **loaded from some Internet address** (URL) through a standard web browser. Users write input data on a page, visualized by the web browser, the data is processed on a web server and the results are shown again on a page in the web browser. For our web application, we are going to use **Flask**, a light Python library, which allows creating **web applications with the programming language Python**. - -Next are the steps for the implementation of the "Numbers Summator" web application. - -#### Empty Python Solution - -We'll create an **empty Python project** in PyCharm to organize our application's code: - -![](/assets/chapter-1-images/08.Numbers-sum-web-02.png) - -Then we need to give the project a meaningful name like **"Summator-Web"**. We'll also set the Python interpreter to this one by default: - -![](/assets/chapter-1-images/08.Numbers-sum-web-03.png) - -#### Installing Flask - -Before we start writing code, we need to install Flask. Let's go to PyCharm's settings [**File**] -> [**Settings**] then go to [**Project: Sumator-Web**] -> [**Project Interpreter**]. There we need to click the **`+`** button: - -![](/assets/chapter-1-images/08.Numbers-sum-web-04.png) - -When you find Flask in the window that appears, click **[Install package]**: - -![](/assets/chapter-1-images/08.Numbers-sum-web-05.png) - -If all goes well, you'll receive the following message on the same screen: - -![](/assets/chapter-1-images/08.Numbers-sum-web-06.png) - -#### Creating The Project Structure - -Let's create the structure of our project. To do that, we're going to create a Python file named **`app.py`** where we will keep our program code. Then we need a folder which we'll call **templates** and an HTML file named **`index.html`** which will help visualize our content in the browser. - -![](/assets/chapter-1-images/08.Numbers-sum-web-07.png) - -#### Writing The Application's Logic - -Time to create our application's controls. The aim is to add fields where our numbers will be entered, a button for summing them and a place to display the result. We can achieve this by writing the following code in `templates/index.html`: - -![](/assets/chapter-1-images/08.Numbers-sum-web-08.png) - -This code creates a web form `
` with a field and a button **[Calculate]** which will send the data from the form to our server. Our **Python** `app.py` file will be responsible for data manipulation. Notice the curly braces – they are used to switch between the **HTML** and **Python languages** and come from the **Jinja2** syntax used for creating dynamic web pages. - -After we've written the following code in `app.py`, we can test if our program is working by running it: - -![](/assets/chapter-1-images/08.Numbers-sum-web-09.png) - -Next, we need to write the code which will handle our **request**: - -![](/assets/chapter-1-images/08.Numbers-sum-web-10.png) - -If we click the calculation button now, our program will be able to sum the two digits from the form. Let's run the program again and test whether it's working correctly. Upon entering the numbers **9** and **11**, we'll receive the correct result: - -![](/assets/chapter-1-images/08.Numbers-sum-web-11.png) - -#### Managing Invalid Numbers - -If we try entering **invalid data**, we'll receive an error: - -![](/assets/chapter-1-images/08.Numbers-sum-web-12.png) - -To handle the error, we need to write the following code: - -![](/assets/chapter-1-images/08.Numbers-sum-web-13.png) - -This is not the best solution for error handling, but it will work. - -If we run the program one more time and test it by entering **invalid data**, we'll receive the `Not number/s.` message. - -![](/assets/chapter-1-images/08.Numbers-sum-web-14.png) - -Does all this seem scary? **There's no need to be afraid**. We have a lot more to learn, to reach the level of knowledge and skills required to write web-based applications with ease like in the example above, as well as much bigger and more complex applications. If it all makes little sense, just keep going without worrying. In time, you will remember with a smile how incomprehensible and exciting your first collision with web programming was. - -The purpose of both examples (graphical desktop application and web application) is not to teach you, but to allow you to dive a little deeper into programming, to **fuel your interest** in software development, and to inspire you to study hard. **You have a lot more to learn**, but it is interesting, isn't it? diff --git a/docs/chapter-02-simple-calculations.md b/docs/chapter-02-simple-calculations.md old mode 100755 new mode 100644 diff --git a/docs/chapter-03-simple-conditions.md b/docs/chapter-03-simple-conditions.md old mode 100755 new mode 100644 diff --git a/docs/chapter-04-complex-conditions.md b/docs/chapter-04-complex-conditions.md old mode 100755 new mode 100644 diff --git a/docs/chapter-05-loops.md b/docs/chapter-05-loops.md old mode 100755 new mode 100644 diff --git a/docs/chapter-06-nested-loops.md b/docs/chapter-06-nested-loops.md old mode 100755 new mode 100644 diff --git a/docs/chapter-07-complex-loops.md b/docs/chapter-07-complex-loops.md old mode 100755 new mode 100644 diff --git a/docs/chapter-09-problems-for-champions-part-2.md b/docs/chapter-09-problems-for-champions-part-2.md old mode 100755 new mode 100644 diff --git a/docs/chapter-09-problems-for-champions.md b/docs/chapter-09-problems-for-champions.md old mode 100755 new mode 100644 diff --git a/docs/chapter-10-functions.md b/docs/chapter-10-functions.md old mode 100755 new mode 100644 diff --git a/docs/chapter-11-tricks-and-hacks.md b/docs/chapter-11-tricks-and-hacks.md old mode 100755 new mode 100644 diff --git a/docs/chapter-12-conclusion.md b/docs/chapter-12-conclusion.md old mode 100755 new mode 100644 diff --git a/docs/index.md b/docs/index.md old mode 100755 new mode 100644 index a557472..2f60fbb --- a/docs/index.md +++ b/docs/index.md @@ -1,61 +1,591 @@ -# Python Coding Basics +# Chapter 1. First Steps in Programming +In this chapter, we are going to find out **what programming** is at its core. We are going to become familiar with the idea of **programming languages** and explore the environments for software development (**Integrated Development Environment** – IDEs); we'll see how to work with them, in particular with **PyCharm**. We will write and execute our **first program** written in the programming language Python and then we're going to practice with a few tasks: we will create a console-based program, a graphical application, and a Web application. We will learn how to use **SoftUni's Judge System** to check the correctness of our solutions to the problems in this book. Finally, we'll look at some typical mistakes made during code writing and we're going to learn how to avoid them. -The free book "**Programming Basics with Python**" introduces the readers to writing **programming code** at a beginner level (variables and data, conditional statements, loops, and functions) using the **Python** programming language. +## What Does 'To Program' Mean? -Book Programming Basics with Python - Cover +To program means to give instructions to the computer, for example, *play a certain sound*, *print something on the screen*, or *multiply two numbers*. When there's a series of commands, we have a computer program (script). The computer program's text is called **program code** (**source code** or **just code**). -* [Preface](chapter-00-preface.md) -* [1. First Steps in Programming](chapter-01-first-steps-in-programming.md) -* [2.1. Simple Calculations](chapter-02-simple-calculations.md) -* [2.2. Simple Calculations – Exam Problems](chapter-02-simple-calculations-exam-problems.md) -* [3.1. Simple Conditions](chapter-03-simple-conditions.md) -* [3.2. Simple Conditions – Exam Problems](chapter-03-simple-conditions-exam-problems.md) -* [4.1. More Complex Conditions](chapter-04-complex-conditions.md) -* [4.2. More Complex Conditions – Exam Problems](chapter-04-complex-conditions-exam-problems.md) -* [5.1. Loops](chapter-05-loops.md) -* [5.2. Loops – Exam Problems](chapter-05-loops-exam-problems.md) -* [6.1. Nested Loops](chapter-06-nested-loops.md) -* [6.2. Nested Loops – Exam Problems](chapter-06-nested-loops-exam-problems.md) -* [7.1. More Complex Loops](chapter-07-complex-loops.md) -* [7.2. More Complex Loops – Exam Problems](chapter-07-complex-loops-exam-problems.md) -* [8.1. Practical Exam Preparation – Part I](chapter-08-exam-preparation.md) -* [8.2. Practical Exam Preparation – Part II](chapter-08-exam-preparation-part-2.md) -* [9.1. Problems for Champions – Part I](chapter-09-problems-for-champions.md) -* [9.2. Problems for Champions – Part II](chapter-09-problems-for-champions-part-2.md) -* [10. Methods](chapter-10-functions.md) -* [11. Tricks and Hacks](chapter-11-tricks-and-hacks.md) -* [Conclusion](chapter-12-conclusion.md) +## Computer Programs -## Download The Book +**Computer programs** represent a **series of commands** written in a particular **programming language**, like Python, C#, Java, JavaScript, Ruby, PHP, C, C++, Go, etc. To write commands, we need to be familiar with the **syntax and semantics of the language** we'll be using, in our case – **Python**. In this book, we're going to cover programming in general, as well as Python's particular syntax and semantics. We will examine each step of writing code, starting with the simplest and eventually reaching more complex programming constructs. -Download the book "**Programming Basics with Python**" in **PDF** format: -* TODO +### Algorithms -## Book Editions +Computer programs usually execute some sort of algorithm. **Algorithms** are a series of steps used to complete a task and achieve an expected result - something like a recipe. For example, if we need to fry some eggs, we follow a certain recipe (algorithm): we heat some oil in a pan, then we break the eggs, we wait until they're cooked, and finally, move the pan away from the heat. Similarly, in programming, **computer programs execute algorithms** – a series of commands needed to complete a certain task. If we want to print a series of numbers in ascending order, for example, we need an algorithm. It will go through all the numbers, find the smallest one and print it, then go through the rest of them and do the same until there are no more numbers left. +To create programs, write program code (commands), execute it and other operations that have to do with making programming more convenient, we need a **development environment** (IDE) like **PyCharm**. -This book is available in several versions in different programming languages: -* [Programming Basics with C# (English)](https://csharp-book.softuni.org) -* [Programming Basics with Java (English)](https://java-book.softuni.org) -* [Programming Basics with JavaScript (English)](https://js-book.softuni.org) -* [Programming Basics with Python (English)](https://python-book.softuni.org) -* [Programming Basics with C# (Bulgarian)](https://csharp-book.softuni.bg) -* [Programming Basics with Java (Bulgarian)](https://java-book.softuni.bg) -* [Programming Basics with JavaScript (Bulgarian)](https://js-book.softuni.bg) -* [Programming Basics with Python (Bulgarian)](https://python-book.softuni.bg) -* [Programming Basics with C++ (Bulgarian)](https://cpp-book.softuni.bg) +### Programming Languages, Compilers, Interpreters and Development Environments +**Programming languages** are artificial languages (syntax for expression), designed to **issue commands** which we expect the computer to read, process and execute. With the help of programming languages, we write a series of commands (**programs**) that **tell the computer what to do**. Execution of computer programs can be achieved by using either a **compiler** or an **interpreter**. -## Book Details +**The compiler** translates code from a programming language into **machine code** and for each construct (command) in the code, it chooses an appropriate, predefined fragment of machine code while simultaneously checking the program's text for **errors**. Together, all the compiled fragments represent the original program translated in machine code, exactly how the computer's microprocessor is expecting it. After it's been compiled, the program can be directly executed by the microprocessor in cooperation with the operating system. Compiled programming languages **compile the program** before executing it and find syntactic errors (incorrect commands) during compile time. Languages like C++, C#, Java, Swift and Go work with compilers. -Brief information about this edition: -* Title: **Programming Basics with Python** -* Authors: **Svetlin Nakov & Team** - * Main authors: Boncho Vulkov, Hristo Minkov, Iliya Iliev, Martin Tsarev, Miglen Evlogiev, Milena Angelova, Mirela Damyanova, Nikolay Kostov, Petar Ivanov, Petya Gospodinova, Svetlin Nakov, Tanya Evtimova, Tanya Staneva, Teodor Kurtev, Ventsislav Petrov, Vladimir Damyanovski, Yordan Darakchiev - * Other contributors: Aleksander Krastev, Aleksander Lazarov, Aleksander Peev, Aleksandra Stoycheva, Angel Dimitriev, Ariet Motzeva, Daniel Tsvetkov, Denis Milanov, Dimitar Dzhapunov, Dimitar Tatarski, Dimo Dimov, Diyan Tonchev, Dzhaner Hasan, Elena Rogleva, Hristiyan Hristov, Hristo Hristov, Iskra Nikolova, Ivelin Kirilov, Jordan Liubenov, Julieta Atanasova, Kalin Primov, Kaloyan Nenchev, Kristiyan Pamidov, Luboslav Lubenov, Martin Zhelev, Mihail Georgiev, Natali Dimitrova, Nikola Slavchev, Nikolay Bankin, Nikolay Dimov, Pavlin Petkov, Petar Ivanov, Preslav Mihaylov, Rositsa Nenova, Ruslan Filipov, Simeon Stavrev, Stefka Vasileva, Svetlin Nakov, Teodor Kurtev, Tonyo Zhelev, Tsvetan Iliev, Vasko Viktorov, Venelin Bekyarov, Ventsislav Petrov, Yanitsa Vuleva, Yulian Linev, Zahariya Pehlivanova, Zhivko Nedyalkov -* ISBN: **978-619-00-1403-4** (9786190014034) -* Edition: **Faber Publishing, Sofia, Dec 2021** (expected) -* License: **CC-BY-SA** -* Source code: https://github.com/SoftUni/Programming-Basics-Book-Python-EN +Some programming languages don't use a compiler but are **directly interpreted** by specialized software called an interpreter. **The interpreter** is a **program that executes programs**, written in some programming language. It executes the program's commands in sequence and understands not only single commands and series of commands but also other language constructs (checks, iterations, functions, etc.). PHP, Python and JavaScript are languages that work with an interpreter and are executed without the need to be compiled. Due to lack of preliminary compilation, interpreted languages' errors are found during run time, after the program has already started working. - +**The development environment** (Integrated Development Environment – **IDE**) combines traditional instruments for software development. In the development environment we write code, compile and execute programs. Development environments incorporate a text editor for writing code, a **programming language**, **a compiler or interpreter**, an **execution environment** where our program is executed, a **debugger** that traces our program and looks for errors, **instruments for design and user interface** as well as other instruments and add-ons. + +**Development environments** are convenient because they incorporate everything necessary to develop a program, so there's no need to leave the environment. If we don't use a development environment, we'll have to write code in a text editor, compile it with a command from the console, execute it with another command from the console and write additional commands, when needed, which would cost a lot of time. This is why most programmers use IDEs for everyday work. + +Programming with **Python** is usually done in the development environment **PyCharm** which is developed and distributed by JetBrains. You can download it from: [https://www.jetbrains.com/pycharm](https://www.jetbrains.com/pycharm). +Here's what the PyCharm environment looks like in action: + +![](/assets/chapter-1-images/PyCharm-IDE-in-action.png) + +Alternatives to PyCharm for writing code in Python are **Visual Studio Code** (https://code.visualstudio.com), **Atom** (https://atom.io), **Eclipse for Python** (https://www.eclipse.org) together with the add-on **PyDev** (https://pydev.org) and others. In this book, we'll use the development environment PyCharm. + +Alternatives to desktop development environments (IDE) are online environments for Python programing such as [**Repl.it**](https://repl.it/languages/python3) and [**PythonAnywhere**](https://www.pythonanywhere.com). They're great for testing short examples, when we cannot install an IDE locally, or when we want to easily share our code with colleagues. Here's an example of how to execute **Python code** in **Repl.it**: + +![](/assets/chapter-1-images/Python-code-in-Repl.it.png) + +### Low-Level, High-Level Languages and Runtime Environments + +A program is, in essence, a **set of instructions** that ask the computer to carry out certain tasks. They are entered by the programmer and **executed unconditionally by the machine**. + +There are different types of **programming languages**. **Lowest-level** languages can be used to write the very **instructions commanding the processor** - **Assembler** is one such language. Higher-level languages can be utilized to create an operating system, drivers for managing hardware (video card drivers, for example), web browsers, compilers, engines for game graphics (game engines) and other system components and programs. Even higher-level languages like **JavaScript**, **C#** and **Python** are used to create application software, like programs for reading mail or chatting. + +**Low-level languages** command hardware directly and require a lot of effort and a vast number of commands, to carry out a certain task. **Higher-level languages** require less code to achieve the same result, but have no direct access to hardware. They are used to develop application software like web and mobile applications. + +Most of the software we use daily like music players, video players, GSP programs, etc. is written on high-level **languages for application programming** like Python, JavaScript, C#, Java, C++, PHP, etc. + +**Python is an interpreted language** which means we write commands and they're executed immediately after running the program. As a result of that, we will realize we've made a mistake in our code only after we've started our program and reached the incorrect command. In cases like these, **IDEs** like PyCharm are extremely helpful as they check our code while we're writing it and alarm us of potential issues. After we've written our code and want to test it, we can save it in a file with extension **`.py`**. + +## Python Interpreter: Installation and Use + +To program in Python, we first need to **install a Python interpreter**. It executes commands and runs programs, written in Python, and is essential if we want to use Python on our computer. + +### Installing The Python Interpreter + +Installing Python is quite simple. Just go to https://python.org/downloads and download the latest version for your platform. + +![](/assets/chapter-1-images/Python-download.png) + +On **Windows**, the installation is a straightforward process of clicking **[Next]**, **[Next]** and **[Finish]**. On **Linux**, you need to use a package installer like `sudo apt-get install python3`. + + + +
Use Python version 3.x or newer. Python 2 is outdated technology and although it's accessible by default on many systems, it's problematic and many of the examples in this book won't work on it.
+ +## Starting The Python Interpreter + +After the Python interpreter has been installed, we can **get it started** and have a tinker at it. If your environment is Windows, use the **[Start]** menu and find the application you just installed – 'Python 3.7 (64-bit)', for instance. On a Linux / MacOS environment, write the command `python3` in the console. Here's what the Python interpreter should look like on Windows: + +![](/assets/chapter-1-images/Python-3.7-Shell.png) + +### Working with The Python Interpreter + +Python is an **interpreter** and it can be used in **command mode**: we write a **command**, it's executed and we receive the **result**. The simplest command we can use is to make Python calculate a numeric expression – `2 + 3`, for example: + +![](/assets/chapter-1-images/Python-shell-calculate-2-plus-3.png) + +As we can see, the answer is correct: `5`. +Let's try a few more commands: store the value `5` in a variable named `a` and print the result of `2 * a`: + +![](/assets/chapter-1-images/Python-shell-calculate-2-multiplied-by-a.png) + +**Play around** with the Python interpreter yourself. Try calculating **1234567890 * 234567890 * 34567890**. Did it work? Try using an **incorrect command** (write your name, for example). Try calculating `2 ** 20` and guessing what that might be. Have a go at printing the text *"Hello Python, how are you?"* using the command `print("some text")`. Is it working? + +## Computer Programs + +As we already mentioned, a program is a **series of commands**, in other words, it describes a series of calculations, checks, iterations and numerous other operations, which aim at producing a result. +The program is written in text format and the text is called **source code**. It's saved in a file with extension `.py` (`main.py`, for instance), and then it can be executed through your browser or the **console** with the help of **Python Shell**. In **script and interpreted languages**, like JavaScript, Python and PHP, the source code is executed step by step by an interpreter. + +### Problem: A Program That Prints 'Hello' + +Let's start with a very basic example of a short **Python program**. It will print the word *"Hello"* like so: +```py +print("Hello") +``` + +We can execute it by typing in the Python interpreter: +![](/assets/chapter-1-images/Python-shell-print-Hello.png) + +### Problem: A Program That Plays The Music Tone 'A' + +Our next program will consist of a single **Python command** which plays the music tone 'A' (432 hertz) for half a second (500 milliseconds): +```python +import winsound + +winsound.Beep(432, 500) +``` +In a Windows environment we will **hear a sound**. Make sure your speakers aren't muted. On Linux and MacOs, the example won't work. + +### Problem: A Program That Plays a Series of Music Tones: +We can make our last program a bit more complex by creating a loop that passes a series of notes with increasing height to the command: +```python +import winsound + +for i in range(200, 4000, 200): + winsound.Beep(i, 300) +``` +In the example above we make the computer play very briefly (300 milliseconds) each subsequent tone with height 200, 400, 600, etc. hertz until reaching 4000 hertz. The result is something similar to a melody. +We will learn how iterations (loops) in programming work in **chapter** "[Loops](chapter-05-loops.md)", but for now, let's assume that they just repeat a command many times. + +### Problem: Program That Converts Levs (BGN - Bulgaria's currency) , into Euros + +Let's have a look at another simple program that reads a number of levs(BGN) from the user, converts them into euro (divides them by the euro exchange rate) and prints the result. This is a program of **three consecutive commands**. Enter and execute them in sequence: +```python +leva = int(input()) +euro = leva / 1.95583 +print(euro) +``` + +Here's what the **result** of the above series of commands might look like: + +![](/assets/chapter-1-images/Python-shell-leva-to-euro.png) + +We looked at **three examples of computer programs**: single command, series of commands in a loop and a sequence of three commands. Let's now move on to the more exciting bit: writing our programs in **Python** and executing them. + +## How Can We Write a Console Program? + +Let's go through the necessary steps to **create and execute a computer program** that uses a text console (window for entering and printing text) to read and write its data. Such programs are called **console programs**. But first of all, we need to **install and prepare the development environment** where we will write and execute the Python programs from this book and the exercises that go along with it. + +## Development Environment (IDE) +As previously mentioned, we need a **development environment** (IDE) to program. The IDE is a program editor, where we write program code and execute it, discover our mistakes, correct them and start the program again. +- For programming in Python, we use the **PyCharm** environment, suitable Windows, Linux and MacOS operating systems. +- If we are programming in Java we might use **IntelliJ IDEA**, **Eclipse** and **NetBeans**. +- If we are programming in C# we might use **Visual Studio**. + +### Installing PyCharm Community +Let's start by installing the **PyCharm Community** integrated environment (in our example we'll be using version 2018, current as at October 2018). +The Community version of PyCharm is freely distributed by JetBrains and can be downloaded from: [https://www.jetbrains.com/pycharm/download](https://www.jetbrains.com/pycharm/download). + +The installation is typical for Windows - simply use the **[Next]** and **[Finish]** buttons. There's a Linux version available as well. +In the following paragraphs, we've described in detail **every step of the PyCharm Community 2018 installation process**. After we download the installation file and run it, we're greeted with the following screen: + +![](/assets/chapter-1-images/00.PyCharm-01.png) + +We hit **[Next]**, which takes us to the screen you see below: + +![](/assets/chapter-1-images/00.PyCharm-02.png) + +A window with PyCharm's installation panel is loaded: + +![](/assets/chapter-1-images/00.PyCharm-03.png) + +We tick the box which allows us to choose a shortcut depending on our operating system [**.py**] and [**Download and install JRE x86 by JetBrains**], and then click [**Next**]: + +![](/assets/chapter-1-images/00.PyCharm-04.png) + +Then we hit the **[Install]** button. + +![](/assets/chapter-1-images/00.PyCharm-05.png) + +After PyCharm installs, we'll see an information screen, where we can tick a box that says **[Run PyCharm]** which is going to start our IDE. After **PyCharm has started**, a screen similar to the one below will be displayed: + +![](/assets/chapter-1-images/01.Hello-python-01.png) + +That's it. We're ready to start working with PyCharm. + +### Older Versions of PyCharm + +We could also use older versions of PyCharm (version 2016 or 2012, for example) but it's **not recommended** since they don't have the newest capabilities for development and not all the examples in this book will run on them. + +### Online Development Environments + +There are also **alternative environments to develop online**, directly in your web browser. They aren't very easy to use but if you have no other option, you can start your education with them and install PyCharm later. Here are some links: +- Tutorials Point allows writing and executing code online: +[https://www.tutorialspoint.com/online_python_ide.php](https://www.tutorialspoint.com/online_python_ide.php). +- Another useful online development environment for writing and executing Python code is Repl.it: [https://repl.it/languages/python3](https://repl.it/languages/python3). + +### Projects in PyCharm + +Before we start working with PyCharm, let's get familiar with the term **PyCharm Project** - it represents the project we're currently working on. + +In the beginning that will be a console program which we'll learn how to write with the help of this book. After some more thorough studying and with time and practice, these projects will turn into applications, web apps and other projects. The PyCharm project uses **logic to group the numerous files** that make up a certain application or component. + +A single **Python project** consists of several **Python source files** (**.py**), configuration files and other resources. Every Python source file can have one or more **classes** and **functions**. **Classes** contain **functions**(actions), which are comprised of a **series of commands**. It may seem complicated, but in larger projects, this structure is extremely convenient and allows for the good organization of our work files. + +# Problem: Creating a Console Program 'Hello Python' + +Let's get back to our console program. Now that we have PyCharm installed, we can start it. Then we will create a new project: **[Create New Project]**. + +![](/assets/chapter-1-images/01.Hello-python-01.png) + +We will give our project a **meaningful name**, such as `FirstStepsInProgramming`: + +![](/assets/chapter-1-images/01.Hello-python-02.png) + +PyCharm will create an **empty project** for us and we can add Python files to it. We'll add a new Python file - **[File]** or right-click on our project -> **[New]** -> **[Python File]** and give it a meaningful name like `HelloPython.py`. + +We can adjust the version and location of the Python interpreter, which we're going to be using. We must have a Python interpreter, otherwise, we won't be able to execute the programs we've written. It's possible to have more than one version of Python on the same computer but for ease of use, in the beginning, **just install the latest version and use that**. If you haven't already installed Python, please do so before you continue. + +### Writing Program Code + +Writing Python code requires no additional preparation – creating a file with the `.py` extension is all we need. So let's directly proceed with writing our first line of code. We will write the following command: +```python +print('Hello Python') +``` +Here's what our program might look like in PyCharm: + +![](/assets/chapter-1-images/01.Hello-python-03.png) + +The `print('Hello Python')` command allows us to print the text message `Hello Python` on the console. The message needs to be surrounded with quotes, signifying text. + +This command is quite typical for programming: we call the function `print(...)` and pass the text literal `'Hello Python'` as its parameter. + +### Starting The Program + +To start the program we need to press **[Ctrl + Shift + F10]** or right-click – **[Run]**. If there are no errors, the program will execute. The result will be displayed on the console: + +![](/assets/chapter-1-images/01.Hello-python-04.png) + +The output from the program is the following text message: +```python +Hello Python +``` +The **'Process finished with exit code 0'** message is displayed at the end of the PyCharm console after the program has been executed, to signify that the program has finished with no errors. + +### Testing in The Judge System + +Testing the solutions to the problems in this book is completely automated via the **Judge System**'s website: [https://judge.softuni.org](https://judge.softuni.org). The solutions are judged immediately by the system. Each solution goes through a series of tests that are hidden; every test that passes grants the user certain points. + +The program we just wrote can be tested here: [https://judge.softuni.org/Contests/Practice/Index/1046#0](https://judge.softuni.org/Contests/Practice/Index/1046#0). To do that, simply paste the entire source code in the black field and choose **Python code** as is shown below: + +![](/assets/chapter-1-images/01.Hello-python-05.png) + +Then we need to send our solution by clicking the **[Submit]** button. The system returns a result in a few seconds which is displayed in the table of submitted solutions. If necessary, we can hit the 'Refresh' button at the upper right-hand corner of the table of submitted solutions: + +![](/assets/chapter-1-images/01.Hello-python-06.png) + +In the table, the Judge System will display one of the following **possible results**: +- A number of points (between 0 and 100), when the submitted code is compiled successfully (there are no syntactic errors) and can be tested. +- If our solution is **completely correct**, all tests are marked in green and we receive **100 points**. +- If our solution is **incorrect**, some tests are marked in red and we receive less than 100 or 0 points. +- If there are syntactic errors in our program, we receive a **compile-time error message**. + +### Test Your Tone-Playing Programs + +Now that you've learned how to **execute programs**, you can test the sample note-playing programs you have above. Have fun with them, try out different things. Try changing them and playing with them. Swap the `print('Hello Python')` command with `windsound.Beep(432, 500)` and add `import windsound` at the top, then start your program. Check whether your computer sound is on and turned up. If you're using an online development environment, you won't hear anything, because the program isn't executed on your computer, but somewhere else. The `windsound` Module may not work with some operating systems like Linux and MacOS. + +## Typical Mistakes in Python Programs + +One of the usual mistakes beginners make is mixing up **capital and lowercase letters**. However, they matter when we call commands and can impede proper functioning. Here's an example of such a mistake: +```python +Print('Hello Python') +``` + +In the example above, `print` is written incorrectly and the capital letter needs to be changed to lowercase. + +
In Python we don't use a semicolon (;) at the end of each command. Commands are separated by a new line or by indentation.
+ +A missing **quotation mark** or **closing bracket** can also cause issues – the program will either **function improperly** or **not execute at all**. Such mistakes are hard to notice, especially with larger amounts of code. Here's an example: +```python +print('Hello Python) +``` + +This program will return an **error** and the code will be underlined to draw the programmer's attention to the missed closing bracket. + + ![](/assets/chapter-1-images/01.Hello-python-07.png) + +## What Have We Learned from This Chapter? + +First of all, we learned **what programming is** – **issuing commands written in a programming language** that the machine can understand and carry out. We also found out what a **computer program** is – a **series of commands** that aim to achieve a certain result. We gained some basic knowledge of the **Python programming language** and learned **how to create simple console programs** using PyCharm. Then we examined **Python's program code structure**. We looked at printing with the function **`print(...)`** and starting the program with **[Ctrl + Shift + F10]**. And last but not least, we now know how to test our code in **SoftUni's Judge System**. + +Top work! Let's now tackle the **exercises**. You do remember that learning how to program involves a lot of code writing and problem-solving, right? Let's do just that and put what we've learned into practice. + +## First Steps in Programming – Problems + +Welcome to the exercises. We are now going to write a couple of console applications, which will help us take a few more steps into programming. After that we will show you how to program something more complex – programs with a graphical and web user interface. + +### Problem: Expression + +Write a console-based **Python** program that **calculates** and **prints** the value of the following numerical expression: +

(3522 + 52353) * 23 - (2336 * 501 + 23432 - 6743) * 3

+Note: you are **not allowed to previously calculate the value** (for example with Windows Calculator). + +### Hints and Guidelines + +Create a new Python file and name it **Expression**. Then we need to **write the code** which will calculate the numeric expression above and print its value on the console. Pass the expression to the **`print(...)`** command by writing it within its brackets: + +![](/assets/chapter-1-images/02.Expression-01.png) + +Start the program with **[Ctrl + Shift + F10]** and check whether the result matches the one from the picture: + +![](/assets/chapter-1-images/02.Expression-02.png) + +### Testing in The Judge System + +Test your solution here: [https://judge.softuni.org/Contests/Practice/Index/1046#1](https://judge.softuni.org/Contests/Practice/Index/1046#1). +![](/assets/chapter-1-images/02.Expression-03.png) + +### Problem: Numbers from 1 to 20 + +Write a **Python console program** that **prints the numbers from 1 to 20** on separate lines on the console. + +### Hints and Guidelines + +Create a Python file and name it **`nums_1_to_20.py`**: + +![](/assets/chapter-1-images/03.Numbers-1-to-20-01.png) + +Inside the file write 20 **`print()`** commands, each on a separate line, to print the numbers from 1 to 20 one after another. Some of you may be wondering if there is a more clever way. Don't worry, there is, but we will mention it later on. + +![](/assets/chapter-1-images/03.Numbers-1-to-20-02.png) + +Let's now **start the program** and check whether the result is what we're expecting: +``` +1 +2 +… +20 +``` + +### Testing in The Judge System + +Test your solution here: +[https://judge.softuni.org/Contests/Practice/Index/1046#2](https://judge.softuni.org/Contests/Practice/Index/1046#2). +Now try and **think of a more clever way** we can write this program, to avoid repeating the same command so many times. Look up information for "[for loop Python](https://www.google.com/search?q=for+loop+python)" on the Internet. + +### Problem: Triangle of 55 Stars + +Write a **Python console program** that prints a **triangle of 55 stars** on 10 lines: +``` +* +** +*** +**** +***** +****** +******* +******** +********* +********** +``` + +### Hints and Guidelines + +Create a **new Python file** and name it **`triangle_of_55_stars.py`**. Inside we need to write code that prints our triangle, using 10 print() commands, like this: +```python +print('*') +print('**') +… +``` + +### Testing in The Judge System + +Test your solution here: +[https://judge.softuni.org/Contests/Practice/Index/1046#3](https://judge.softuni.org/Contests/Practice/Index/1046#3). + +Try and **improve your solution** to avoid repeating the same command so many times. Can this be achieved with a **`for`**-loop? Did you manage to invent a better solution (with a for-loop, for example) to the previous problem? The current problem can be solved with a similar, but a little more complex approach (a loop within another loop). It's completely fine if you can't figure it out, you'll remember this problem when we learn about loops in a few chapters. + +### Problem: Rectangle Area + +Write a **Python program** that **receives two numbers a and b, then calculates and prints** the area of a rectangle with sides **a** and **b**. + +### Sample Input and Output +| a | b | area | +| :---: | :---: | :---: | +| 2 | 7 | 14 | +| 7 | 8 | 56 | +| 12 | 5 | 60 | + +### Hints and Guidelines + +Create a **new Python file**. We'll use the following commands to read our numbers: + +![](/assets/chapter-1-images/05.Rectangle-area-01.png) + +What's left is to finish the program so it can calculate the rectangle's area and print it. Pass the product of **`a`** and **`b`** to the already familiar **`print(...)`** command. In programming, we multiply using the **`*`** operator. + +### Test Your Solution + +Test your solution with a few examples. You should receive a result identical to the one you see below (we enter 2 and 7 as input and the program prints 14 – their product, as output): +``` +2 +7 +14 +``` + +### Testing in The Judge System + +Test your solution here: +[https://judge.softuni.org/Contests/Practice/Index/1046#4](https://judge.softuni.org/Contests/Practice/Index/1046#4). + +### Problem: Square of Stars + +Write a **Python console program that reads an integer positive number N** from the console and **prints a square of N stars** on the console, like in the examples below. + +### Sample Input and Output + +| Input | Output | Input | Output | Input | Output | +|-----|-----------|-----|-----------|-----|----------| +| 3 | \*\*\*
\* \*
\*\*\*| 4 |\*\*\*\*
\*  \*
\*  \*
\*\*\*\*| 5 |\*\*\*\*\*
\*   \*
\*   \*
\*   \*
\*\*\*\*\*| + +### Hints and Guidelines + +Create a **new Python file**. To read the number N (2 ≤ N ≤100), we use the following code: + +![](/assets/chapter-1-images/06.Square-of-stars-01.png) + +Finish the program so that it prints a square made up of stars. You may need to use **`for`**-loops. + +**Caution**: this task is more difficult than the rest and is presented to you at this point purposefully. It's marked with a star, to provoke you **to look for information on the Internet**. This is one of the most important skills you have to develop while you're learning to program. This is what you'll be doing every day if you work as a developer, so don't be scared, try it out. If you're having difficulties, you can also ask for help in the **SoftUni's Reddit Community**: [https://www.reddit.com/r/softuni/](https://www.reddit.com/r/softuni/). + +### Testing in The Judge System + +Test your solution here:[https://judge.softuni.org/Contests/Practice/Index/1046#5](https://judge.softuni.org/Contests/Practice/Index/1046#5). + +## Console, Graphical and Web Applications + +With **console applications**, as you've already noticed, **all operations** for reading input and printing output are done on the console. The input data is **entered on the console** and then it is read by the application; the console is also used to **print the output data** after or during the runtime of the program. + +While a console application **uses the text console**, web applications use a **web-based user interface**. **To execute them**, two things are needed – a **web server** and a **web browser**. The **browser** plays the main role in the **visualization of data and interaction with the user**. Web applications are much more pleasant for the user, they look better, and a mouse and touch screen can be used (for tablets and smartphones). Programming stands under all of that, of course. This is why **we need to learn how to program** and we have already made our first tiny steps towards achieving that. + +Graphical (GUI) applications have a **visual user interface**, directly on your computer or mobile device, without a web browser. Graphical applications (also known as desktop applications) contain one or more graphical windows where certain controllers are located (text fields, buttons, pictures, tables and others), which **allow dialog** with the user to be more intuitive. Similar to them are mobile applications on your smartphone or tablet: we use forms, text fields, buttons and other controls and we manage them with program code. This is why we learn to write code now: **code is everywhere in software development**. + +## Problem: Graphical and Web Applications + +We will now build a **basic web application** and after that, a simple **graphical application**, to have a look at what we will be able to create once we progress with programming and software development. We are not going to examine the techniques and constructions used in much detail. Rather, we are just going to have a peek at the arrangement and functionality of what we've created. After we progress with our knowledge, we will be able to develop bigger and more complex software applications and systems. We hope that the examples given below will boost your interest, rather than make you give up. + +## Graphical Application: 'Numbers Summator' + +Write a **graphical (GUI) application** that **calculates the sum of two numbers**. After the numbers are entered in the first text fields, and the button **[Calculate]** is clicked, calculate their sum and display the result in the third text field colored in green: + +![](/assets/chapter-1-images/07.Numbers-sum-01.png) + +We'll use the standard Python graphical library **TKInter** for our application (https://wiki.python.org/moin/TkInter. It enables us to create **graphical (GUI) applications** using the **Python** programming language. + +## Empty Python Project + +Create a **new Python project** named **"Summator-GUI"** in PyCharm: + +![](/assets/chapter-1-images/07.Numbers-sum-02.png) + +Add a new Python file named **summator.py** to the project. Then add **tkinter** as well: + +![](/assets/chapter-1-images/07.Numbers-sum-03.png) + +#### Creating The Basis for The GUI Project + +Next, we need to write the code for our graphical application, starting with the basis: + +![](/assets/chapter-1-images/07.Numbers-sum-04.png) + +We'll need the following components (controls): +* **Entry** – will enter the numbers that need to be calculated. +* **Label** – will serve to statically display text and the result of the calculation. +* **Button** – will calculate the sum of our numbers. + +![](/assets/chapter-1-images/07.Numbers-sum-05.png) + +Let's **initialize and visualize** our controls (widgets): + +![](/assets/chapter-1-images/07.Numbers-sum-06.png) + +And try to start our application with **[Ctrl + Shift + F10]** or right-click + **[Run]**. It should start but **not function correctly**, because we haven't specified what happens when the button is clicked: + +![](/assets/chapter-1-images/07.Numbers-sum-07.png) + +#### Application Logic + +Now we're going to write the code responsible for summing our numbers and displaying the result in the third field. For that to work, we add the **`calculate`** command upon the button's initialization: + +![](/assets/chapter-1-images/07.Numbers-sum-08.png) + +Then we write the **`calculate`** function's code: + +![](/assets/chapter-1-images/07.Numbers-sum-09.png) + +This code **takes the first number** from the **`firstNumberEntry`** field and stores it in the **`first_value`** **variable**. Then it stores the **second number** from the **`secondNumberEntry`** field in the **`second_value`** variable. It **sums** **`first_value`** and **`second_value`** and stores the result in the **`result`** variable. Finally, it **displays the text representation** of the **`result`** variable in the **`resultLabel`** field. + +Let's start the program again using **[Ctrl + Shift + F10]** or right-click + **[Run]** and check whether it's working correctly. Try and calculate **4** + **5**, then **-2.5** + **1.5**: + +![](/assets/chapter-1-images/07.Numbers-sum-10.png) ![](/assets/chapter-1-images/07.Numbers-sum-11.png) + +#### Managing Invalid Numbers + +Entering **invalid numbers** like **'a'** and **'b'** seems to create issues: + +![](/assets/chapter-1-images/07.Numbers-sum-12.png) + +This is due to the **conversion of the information entered in our text field into a number**. If the **value in the field isn't a number, our program returns an error**. We can fix the code to resolve this issue: + +![](/assets/chapter-1-images/07.Numbers-sum-13.png) + +The code you see above **intercepts number-handling errors** (catches exceptions) and in case of an error, **returns a `Not number/s`** value in the result field. If we start our program once more and enter an improper value, the **result is `Not number/s`** and our program continues working as intended: + +![](/assets/chapter-1-images/07.Numbers-sum-14.png) ![](/assets/chapter-1-images/07.Numbers-sum-15.png) + +Does that seem complicated? If it does, that's completely normal. We are at the very start of our programming journey. The example above requires much more knowledge and skills, which we are going to develop using this book and later on as well. Just allow yourself to have some fun with desktop programming. Or bravely move forward to the next example or the next chapter in the book. There will come a time when this becomes easy for you, but you have to put in some effort and be persistent. Learning programming is a slow process involving lots and **lots of practice**. + +### Web Application: 'Numbers Summator' +Now we are going to create something even more complex, but also more interesting: a Web application that **calculates the sum of two numbers**. By entering two numbers in the first two text fields and clicking the **[Calculate]** button, **their sum is calculated** and the result is displayed in the third text field. + +Keep in mind that we are creating a **Web-based application**. This is an application that is accessible through a web browser, just like your favorite email or news website. The web application is going to have a server-side (back-end), which is written in the Python language with **Flask** ([https://flask.palletsprojects.com](https://flask.palletsprojects.com)) technology, and a client-side (front-end), which is written in the **HTML** language (this is a language for visualization of information in a web browser). The Web application is expected to resemble the following: + +![](/assets/chapter-1-images/08.Numbers-sum-web-01.png) + +As opposed to console applications that read and write data in the form of text on the console, Web applications have a **Web-based user interface**. Web applications are **loaded from some Internet address** (URL) through a standard web browser. Users write input data on a page, visualized by the web browser, the data is processed on a web server and the results are shown again on a page in the web browser. For our web application, we are going to use **Flask**, a light Python library, which allows creating **web applications with the programming language Python**. + +Next are the steps for the implementation of the "Numbers Summator" web application. + +#### Empty Python Solution + +We'll create an **empty Python project** in PyCharm to organize our application's code: + +![](/assets/chapter-1-images/08.Numbers-sum-web-02.png) + +Then we need to give the project a meaningful name like **"Summator-Web"**. We'll also set the Python interpreter to this one by default: + +![](/assets/chapter-1-images/08.Numbers-sum-web-03.png) + +#### Installing Flask + +Before we start writing code, we need to install Flask. Let's go to PyCharm's settings [**File**] -> [**Settings**] then go to [**Project: Sumator-Web**] -> [**Project Interpreter**]. There we need to click the **`+`** button: + +![](/assets/chapter-1-images/08.Numbers-sum-web-04.png) + +When you find Flask in the window that appears, click **[Install package]**: + +![](/assets/chapter-1-images/08.Numbers-sum-web-05.png) + +If all goes well, you'll receive the following message on the same screen: + +![](/assets/chapter-1-images/08.Numbers-sum-web-06.png) + +#### Creating The Project Structure + +Let's create the structure of our project. To do that, we're going to create a Python file named **`app.py`** where we will keep our program code. Then we need a folder which we'll call **templates** and an HTML file named **`index.html`** which will help visualize our content in the browser. + +![](/assets/chapter-1-images/08.Numbers-sum-web-07.png) + +#### Writing The Application's Logic + +Time to create our application's controls. The aim is to add fields where our numbers will be entered, a button for summing them and a place to display the result. We can achieve this by writing the following code in `templates/index.html`: + +![](/assets/chapter-1-images/08.Numbers-sum-web-08.png) + +This code creates a web form `` with a field and a button **[Calculate]** which will send the data from the form to our server. Our **Python** `app.py` file will be responsible for data manipulation. Notice the curly braces – they are used to switch between the **HTML** and **Python languages** and come from the **Jinja2** syntax used for creating dynamic web pages. + +After we've written the following code in `app.py`, we can test if our program is working by running it: + +![](/assets/chapter-1-images/08.Numbers-sum-web-09.png) + +Next, we need to write the code which will handle our **request**: + +![](/assets/chapter-1-images/08.Numbers-sum-web-10.png) + +If we click the calculation button now, our program will be able to sum the two digits from the form. Let's run the program again and test whether it's working correctly. Upon entering the numbers **9** and **11**, we'll receive the correct result: + +![](/assets/chapter-1-images/08.Numbers-sum-web-11.png) + +#### Managing Invalid Numbers + +If we try entering **invalid data**, we'll receive an error: + +![](/assets/chapter-1-images/08.Numbers-sum-web-12.png) + +To handle the error, we need to write the following code: + +![](/assets/chapter-1-images/08.Numbers-sum-web-13.png) + +This is not the best solution for error handling, but it will work. + +If we run the program one more time and test it by entering **invalid data**, we'll receive the `Not number/s.` message. + +![](/assets/chapter-1-images/08.Numbers-sum-web-14.png) + +Does all this seem scary? **There's no need to be afraid**. We have a lot more to learn, to reach the level of knowledge and skills required to write web-based applications with ease like in the example above, as well as much bigger and more complex applications. If it all makes little sense, just keep going without worrying. In time, you will remember with a smile how incomprehensible and exciting your first collision with web programming was. + +The purpose of both examples (graphical desktop application and web application) is not to teach you, but to allow you to dive a little deeper into programming, to **fuel your interest** in software development, and to inspire you to study hard. **You have a lot more to learn**, but it is interesting, isn't it?