Data and structure types

Cards (49)

  • Declaring a variable
    The process of telling the computer what data type it is storing
  • Categories of data
    • Text
    • Image
    • Number
    • Sound
  • File types
    • .mp3
    • .jpg
    • .doc
    • .xls
  • .mp3
    Storing and transferring music on computers, smartphones, online and portable MP3 players
  • .jpg
    A widely used compressed image format for containing digital images
  • .doc
    An attachment is simply an additional file sent with an email message/text
  • .xls
    Used for files saved as Microsoft Excel worksheets
  • .doc and .xls are likely to contain more than one type of data
  • Data types that can be seen in a video game screenshot
    • Character
    • Integer
    • String
    • Boolean
  • All data, whether they are text, audio, an image or a video, are stored as a series of 1s and 0s which the computer needs to know how to interpret
  • Real numbers include integers, and a variable declared as a float could therefore hold an integer. More memory is used to store a float, so there is a separate data type of integers
  • Integer
    Numeric variable without a decimal. Can be whole numbers and positive or negative. Can be written as "int" or integer
  • Real (Float)

    Real numbers include all of the integer numbers that exist to infinity plus all of their fractions and decimals
  • Character
    A character data type is used to store a single, alphanumeric character: a character representing a letter, number or symbol
  • String
    A string is more useful than the character data type as it can hold a list of characters of any length: it therefore represents alphanumeric data and symbols
  • Boolean
    The Boolean data type can only represent two values: true or false
  • age
    Real (float)
  • We do not explicitly specify the variable's data type in Python
  • In most programming languages, string indexing starts at 0 so the first letter is at position 0. However, some languages start indexing at 1 and pseudocode can use string indexing beginning at either 0 or 1. In this book string indexing in pseudocode starts at 0
  • String has been given a value
  • 'found' hasn't been defined
  • Should be an AND instead of OR
  • Algorithm to count the number of times a particular character occurs in a string
    1. Inputchar = char(input("Please enter your character: "))
    2. Inputstring = str(input("Please enter your string: "))
    3. count = 0
    4. For char in Inputstring
    5. If char == Inputchar
    6. Count = count + 1
    7. print("You entered(Inputchar)(count)(times")
  • Algorithm to check if the word 'variable' appears in a set of notes and count the number of times it appears

    1. notes = input"Enter your notes.")
    2. Count = cont.lower().count("variable")
    3. print(f"variable was in your notes{count}time(s)")
  • Algorithm to allow a user to enter their first name and surname and print a message

    1. firstName = input("Please enter your first name: ")
    2. surname = input("Please enter your surname: ")
    3. print(f"Hello {firstName} {surname}. How are you?")
  • Sometimes the computer can become confused as to whether a variable is a number or a string and produce an error message when a string is used in a mathematical calculation
  • In some languages you cannot mix numbers, string and literal text in print statements. The numbers would have to be converted into strings using this method
  • Data types include

    • Integer and real numbers
    • Characters
    • String
    • Boolean
  • A real data type includes numbers with decimal places
  • A string variable contains a list of characters
  • Each character in a string has an index indicating its position
  • String can be manipulated in many ways. For example, they can be split up or concatenated
  • String can be converted to integer and real numbers and vice versa
  • Real-world situations where storing multiple items of data is desirable
    • To store customer information
    • To store product details
    • To store order history
  • Algorithm to ask a user to enter the names of five cars into an array and then print the array
    1. cars = []
    2. for i in range(5):
    3. car_name = input(f"Enter the name of car {i + 1} : ")
    4. cars.append(car_name)
    5. print("List of cars" , cars)
  • Algorithm to return the array indexes of all the letters in a given string
    1. word = input(' enter word: ')
    2. for a in range (len(word)
    3. print(alphabet[word[a]], end =' ')
  • Algorithm to find the minimum value and mean of an array of marks

    1. mark = []
    2. low = 0
    3. high = 100
    4. For i in marks:
    5. X = marks[i]
    6. IF high > low:
    7. i = i + 1
    8. ELIF high < high:
    9. high = x
    10. i = i + 1
    11. print("The lowest score is : ", low)
    12. print("The highest score is: ", high
  • Algorithm to create a new array 'pass' and copy all the marks of 5 and over into this new array
    1. mark = [6, 9, 2, 5, 8, 3, 9, 9, 10 ,9, 5, 7, 10]
    2. pass = []
  • Algorithm to amend all of the results in an array 'exam1' based on a new mark scheme
    1. exam1 = [1,2,4,7,99,23]
    2. newMarks = []
    3. for a in range(len(exam1)):
    4. if exam1[a] < 50:
    5. newMark = exam1[a] + 5
    6. newMarks.append(newMark)
    7. elif exam1[a] > 50:
    8. newMark = exam1[a] + 10
    9. newMarks.append(newMark)
    10. print(newMarks)
  • Data structures
    • Lists
    • Tuples
    • Sets
    • Dictionaries