O GoConqr está de visual novo! Conte para nós o que você achou.

Mapa mental

course 3 AFEC

emily ! Inglês

Conteúdo do mapa

course 3 AFEC

  1. sometimes you may need to store multiple variables, for example, if you need a list of names, you can have three variables, name_1, name_2, name_3, and store the names using those variables

  2. if you have a list of items, such as strings, that you want to group together within the program, you can use a 'list', which is a Python data structure

    • to create a list, you start by naming a variable and placing the equals sign = in front of it
      • after the equals sign, type a square bracket, list all the items you want to group (make sure to put double speech marks around each seperate item of the group) and end the list with another square bracket
        • if you want to print the entire list, just use the print function like this: print(state the variable here)
          • when you print, the entire list (including the square brackets) will appear
  3. to print a specific part of a list, such as the first item, use print(name of variable[item number])

    • for example, print(phrases[0])
      • 0 always refers to the first item, 1 to the second, etc.
  4. to output a random item, use 'import.random' at the start of the programme

    • then, to pick something random, type print(random.choice(name of variable here))
  5. a while loop can be used within coding: for example, while True: and then list conditions

    • if you want something to go on forever, use a while True loop, and write all the code below that you want to go on forever
  6. creating dictionaries

    • a data structure containing a series of keys
      • each unique key has a data value- integer, string, etc.- called key:value pairs
    • a dictionary is defined by curly brackets, a colon after the key and a comma after the pair
    • similar to lists
    • an example is "hello": "Hello, how are you?"
      • a full example is: my_dictionary = {"hello": "Hello, how are you?", "goodbye": "Goodbye, see you soon!" (next line) print(my_dictionary["goodbye"])
        • this will print the full phrase (not just goodbye)
    • for item in variable name: (next line) print(item), this code will print all keys
      • to list all values, use code as below
        • for value in variable.values(): (next line) print(value)
      • to print a specific
  7. validation is a way to check that the program is not going to produce an error.

    • for example, using a dictionary to list some data (like football world cup winners), if a year is stated and there is no information for that, instead of an error coming up, you can just print 'we don't have that information'
  8. if you want to output key and values, use the code as listed, (world_cup_winners is the variable in this case); for key in world_cup_winners: (next line) print("{} -> {}".format(key, world_cup_winners[key]))

    • this will list each key and value, one key and one value per row. The key will appear on the left and there will be an arrow (->) pointing to the value, on the right

Informações

Descrição
Mapa Mental sobre course 3 AFEC, criado por emily ! em 06-05-2020.
Criado por
emily ! · mai 2020
Atualizado
31 mai 2020
Visualizações
0
Avaliação

Fale Conosco

Sobre o que é sua mensagem?

O que você acha do novo visual?

Você gostou?