Pular para o conteúdo principal

Logic Programming With Python - 02

 Basic concepts

Some basic concepts are very important for learning programming. They are variables, mathematical operators, logical operators and loops.

We will study these concepts through a practical approach using the Python language.

Python is a general purpose programming language that has become very popular for being easy to learn and use, having several frameworks and libraries , being versatile, efficient, fast, flexible and having good support for machine learning.

Our goal is not to deepen learning about Python. For more details on Python, visit the official language

page https://www.python.org/

But we will use language Python to learning the basic concepts of Programming Logical


Then, lets go


To begin is need install the Python. We will go use the 3.x version.

download

You can use vim, notepad, notepad++ or any other text editor. To develop the code examples for this article


Variables

We can describe a variable as a part of memory where we store data to process or display through the program


Before starting the examples We should know the two basic commands for inputting and outputting Python data. They are "print" and "input". The "print" command is used to display messages on the console and the "input" command  is used to capture what the to user  dictates on the console. 

Ex: If we want a program to add two values ​​and display the result to the user.

In Python we can do the following example:


program 01



This program has four lines. In lines one and two were stored the values 10 and 5 in the variables number1 and number2 respectively. In line three, the sum between variables number1 and number2 was stored in the result variable. In line four, the result will be display to user.

OBS: To execute the program open the terminal and run the command python program01.py


program 02

In this program We want to store the username in the name variable and display the message "Your name is " _typed_name



This program has three lines. On the first line, the message "What's your name"  will be displayed to the  user via the print command. On the second line, the name entered by the user will be stored inside the variable name. On the thirth line the message displayed to the user will be 'Your name is '  concatenate with the name sotered inside the vairiable name.


To execute the program open the terminal and run the command python program02.py



Comentários

Postagens mais visitadas deste blog

Validando Documentos com Fluent Validation, DocsBRValidator e .net Core 6.0

  Introdução A necessidade de utilização das bases de dados para construção de estratégias de negócios através  de técnicas de Ciência de Dados torna necessário que as aplicações sejam cada vez mais cuidadosas para a validação dos campos que serão salvos nas bases dos sistemas. Esses cuidados tem o objetivo de melhorar a qualiade das informações que serão fornecidas para sistemas de Inteligência artificial, mineração de dados, etc . Neste artigo será apresentada a construção de uma solução console que utiliza o Fluent Validation, DocsBRValidator  e o .net Core 6 para validar o número do CPF fornecido pelo usuário.   FluentValidation FluentValidation é uma bliblioteca .Net criada para construção de regras de validação. Com essa biblioteca  podem ser definidos a obrigatoriedade de campos , os tamanhos, os tipos e a formatação.   DocsBRValidator DocsBRValidator é uma biblioteca que possui a regra de validação para os principais documentos brasileiros como CPF, CNPJ,  RG, CNH, Titulo de El

Criando uma calculadora Android com o Kotlin

Resumo Aprender a programar para Android exige a absorção de conceitos básicos que são mais naturalmente entendidos quando aplicados em algum projeto de desenvolvimento. Objetivando introduzir o contato com o Kotlin para Android, foi criado neste artigo um aplicativo simples de calculadora que possibilita a apresentação do tratamento de eventos de botões, uso de expressões regulares e utilização de um método estático. Introdução O desenvolvimento de aplicativos envolve o entendimento de conceitos que devem ser naturalizados pelos desenvolvedores. Uma das formas mais comuns de se naturalizar os diversos recurso de uma plataforma é desenvolver projetos que demonstrem o funcionamento prático dos conceitos implementados. O aplicativo   Calculadora foi desenvolvido por possibilitar o contato inicial do desenvolvedor com os conceitos de tratamento de eventos, métodos estáticos e expressões regulares. O código desenvolvido buscou implementar estes conceitos de maneira introdutória. Não fo

Logic Programming With Python - 03

Control Flow We often need to run specific code for certain conditions or we must run a code snippet many times. Toward we have this behavors we need of structures of control flow. Basically these structures are divided into conditional and repeating structures.  Conditional structures allow select code snippets for specific conditions while Loop structures allow the execution of code snippets many times. Conditional structures in Python The logical conditionals usein Python are: Equals:  a == b Not Equals:  a != b Less than:  a < b Less than or equal to:  a <= b Greater than:  a > b Greater than or equal to:  a >= b These conditions are fundamental to statement logical and loops Simple if-statement. In this example were declared two variables: a and b. In the if-statement  was defined the condition b > a. As b is equal the five and a is equal to three the message "b greater than a" will show to the user. Code Block In Python, The code block is defined through