GoConqr has a new look! Let us know what you think.

Flashcards

Independent Study: Arrays

David Hewson English 10 cards

Cards in this deck (10)

  1. 1How do you create an array for strings?To create an array you need a variable name, square brackets and commas between each element in the array.
  2. 2Give an example of an array for a string.ShoppingList = ["milk", "eggs", "fish"]
  3. 3How do you print an array?You need "print ("")" and the variable. It should look like the following:
    print (ShoppingList)
  4. 4What is an element?The individual item in an array. E.g.
    ShoppingList = ["milk", "eggs", "chicken"]
    An element would be "milk" or "chicken".
  5. 5Give an example of an element in the following array: ShoppingList = ["milk", "eggs", "bread"]It could be either "milk", "eggs" or "bread".
  6. 6What is the code for adding an element to an array?ShoppingList = ["milk", "eggs", "banana"] ShoppingList.append("sausage")
  7. 7What is the code for removing an element from an array?ShoppingList = ["milk", "eggs", "banana"]
    ShoppingList.remove("banana")
  8. 8How do you find the position of an element in an array?You can find the position of an element in an array in the following code:
    ShoppingList = ["milk", "eggs", "banana"]
    position = ShoppingList.index("eggs")
    print (position)
  9. 9How do you search for an element in an array?ShoppingList = ["milk", "eggs", "banana"]
    print ("Enter a shopping item to search for")
    item = input()
    if item in ShoppingList:
    print ("That item is on the shopping list")
    else:
    print ("That item is not on the list")
  10. 10How do you choose an element randomly from an array?You can choose an element at random with the following code:
    import random
    DieNumbers = [1,2,3,4,5,6]
    DieRoll = random.choice (DieNumbers)
    print (DieRoll)

Information

Description
Flashcards on Independent Study: Arrays, created by David Hewson on 22/11/2020.
Created by
David Hewson
Views
1
Rating

More on Arrays and Data Structures

Feedback

What is it about?

What do you think of the new look?

How do you like it?