¡GoConqr estrena diseño! Cuéntanos qué te parece.

Mapa mental

coding in Pythone

Seth Hartley Inglés

Contenido del mapa

coding in Pythone

  1. Procedural programming (A set of commands that run in order)

    • Computers don’t think for themselves Everything they do follows a set of clearly defined instructions The simplest programs are Procedural – they are just a sequence of commands that run in order
    • Functions tell a program to do something Each function does a different thing Examples: print() - displays some text in the console input() - gets some text from the keyboard round() - rounds a number to a given decimal place
    • Methods are functions that are contained in a group of functions called an object For our purpose they are used the same way Examples: Random.randint() - generates a random whole number Random.random() - generates a random decimal number between 0 and 1 Turtle.forward() - moves a turtle forward
      • Some functions need more than one argument round() needs to know what number to round and how many decimal places to use If a function requires more than one argument, they are separated by commas Example round(4.3266443, 2) – this will round 4.3266443 to two decimal places, resulting in 4.33
    • Notice how every function and method ends with ()? Most functions need extra data to run The print() function needs to know what to print This extra data is called an argument. The argument goes in the brackets after the function Examples: print(“hello world”) Turtle.forward(50)
  2. loops and variables (Repeating values)

    • One simple way we can change the flow of a program is by using a iteration. Iteration is the process repeating a section of code multiple times. A loop is the section of code that repeats under specified circumstances.
      • Loops are used to repeat code. We use a loop when we identify a sequence of instructions that will be repeated multiple times. Sometimes this is just one instruction that is repeated, sometimes it is many instructions.
      • Conditional loops (A statment that may be true or fase)
        • Using conditions, we can control when the code loops and stop it looping when we want it to. A condition is a statement that must be true in order for the loop to happen. If the condition becomes false, the loop stops.
        • A while loop can be added into code to make certain lines repeat.
        • The condition is a statement that may be true or false.
    • A while loop can be added into code to make certain lines repeat.
      • We’ll look more at conditions later, but the simplest condition for a while loop is simply to use the keyword, True. Using True ensures that the condition is always true, and therefore the indented commands will run over and over forever.
      • Probably the most important part of learning to program is understanding variables A variable is simply a name you assign to a value. This name can be used in place of the variable. As the name suggests, the value can vary (change) throughout the program.
  3. console Programming (inputs)

    • There are many ways to run Python programs We can download and install a free Python IDE, such as Thonny Or we can run Python in a browser window using a website like replit.com or trinket.io In school we will use Thonny, but all tasks can be completed using any Python editor, including online ones
      • A + symbol can be used to combine strings together into bigger strings This is called concatenation Edit your Task 2a code so it looks like this: Your code will now concatenate the two strings ("hello" and "Bob") into one big string and display it.
        • All programming languages allow us to store data for later use. Data is stored in a named store called a variable. It is called this because the data inside it varies – i.e. it can change. We can name variables anything we like, as long as it starts with a letter.
          • input() is the second function we’re going to look at. Reminder: A function is a command which performs an action. input() displays a prompt in the console then waits for the user to type a response on the keyboard.
    • To make programs far more useful, we can get inputs from the user and store those in variables, which we can use later.
  4. Data types( Named areas of memory)

    • Variables are named areas of memory used to store values that can change throughout the program. There are different types of value that need to be stored in different ways. Whole Numbers (or integers) are stored using binary Words (or strings) are stored using ASCII Real numbers (or floats) are stored using floating point binary True or False (or Boolean) can be stored using a single 1 or 0
      • Mathematical operations can be performed on Integers and Floats using the following operators: + (add) - (subtract) * (multiply) / (divide) Python follows the rules of BIDMAS, and brackets can be used.
    • Sometimes, your variable will not be the data type you want. Maybe you’ve stored an input from the user (which will be a string), but you want it to be an integer. Maybe you have a number (real or integer), and need to add it onto the end of a string. Casting is the act of changing a variable’s data type. To cast a variable, you use the int(), str() or float() functions

Información

Descripción
Mapa Mental sobre coding in Pythone, creado por Seth Hartley el 08/09/2021.
Creado por
Seth Hartley
Visitas
1
Historial
  • Creado por Seth Hartley · 8 sep 2021
  • Copiado por Seth Hartley · 8 sep 2021
Valoración

Escríbenos

¿Sobre qué es tu mensaje?

¿Qué te parece el nuevo diseño?

¿Te gusta?