Topic 2: Programming fundamentals

Cards (44)

  • What is the purpose of variables in programming?
    Variables store data in memory locations that can change during program execution.
  • How does the value of a variable change during program execution?
    The value of a variable can change as the program runs and processes data.
  • What is an identifier in programming?
    An identifier is a unique name that refers to a location in memory where data is stored.
  • What defines the type of data that can be stored in a variable?
    The data type defines the type of data that can be stored at the memory location and the operations that can be performed on it.
  • Why can't you multiply two words in programming?
    You cannot multiply two words because multiplication is not defined for string data types.
  • In some programming languages, when are variables declared?
    Variables are declared at the start of a program to reserve the appropriate amount of memory.
  • How does variable declaration differ in Python compared to other languages?
    In Python, variables do not need to be declared; the data type is inferred from the assigned value.
  • What happens when you assign a value like -23 to a variable in Python?
    The variable will be stored as an integer.
  • Why is it important to understand different data types in programming?
    Understanding different data types is crucial for effectively working with variables in programs.
  • What are the typical memory requirements for different data types?
    • Integer: 2 or 4 bytes
    • Single: 4 or 8 bytes
    • Character: 1 byte
    • String: 1 byte per character
    • Boolean: 1 byte
  • What type of data does an integer variable store?
    An integer variable stores whole numbers such as 3, 45, or -453.
  • What type of data does a single variable store?
    A single variable stores numbers with a fractional part such as 34.450 or 4.0.
  • What does a character variable store?
    A character variable stores a single character, which can be a letter, digit, punctuation mark, or symbol.
  • What does a string variable store?
    A string variable stores zero or more characters and can be empty, just one character, or several characters.
  • What values can a Boolean variable have?
    A Boolean variable can have the value True or False.
  • What is the focus of section 7.1 in the study material?
    Programming fundamentals
  • Why might different programming languages have different names for data types?
    Because each programming language has its own syntax and conventions
  • How many bytes might an integer require in different programming languages?
    It can require either 2 bytes or 4 bytes
  • What is the purpose of assignment statements in programming?
    To assign values to variables
  • What is an example of a constant in programming?

    VAT_RATE = 0.2
  • What are the two main benefits of declaring a constant?
    1. Easier to update values in one place; 2. Code is easier to read and understand
  • How are constants typically declared in Python?
    By using an assignment statement
  • What convention is used in Python to indicate a constant?
    Identifiers for constants are written in uppercase
  • What is the general structure of input and output statements in programming?
    • Input statement prompts the user for data
    • Output statement displays results to the user
  • What pseudocode would you write to ask the user for their name and display a greeting?
    my_name = input("Please enter your name: "); print("Hello", my_name)
  • What types of operations can be performed on numerical data types?
    Arithmetic operations and comparison operations
  • What are the arithmetic operations that can be performed on numerical data types?
    • Addition
    • Subtraction
    • Multiplication
    • Division
    • Exponentiation
    • Integer division (DIV)
    • Modulus (MOD)
  • What is the result of the operation 25+25 +3 3?

    2828
  • What does the DIV operator do?
    Performs integer division
  • What does the MOD operator return?
    The remainder of integer division
  • How do you declare variables for integer and real numbers in Pascal?

    Var num1, num2: integer; Var answer: real;
  • What is casting in programming?
    Changing the type of a variable value from one type to another
  • How would you convert a string to an integer in Python?
    Using the int() function
  • What happens when you add two strings in Python?

    They are concatenated
  • What is the corrected pseudocode to add two numbers input as strings?
    num1 = int(input("Please enter first number")); num2 = int(input("Please enter second number")); sum = num1 + num2
  • What does the float() function do?
    Changes a string variable to a floating-point number
  • What are the built-in functions for string manipulation in programming?
    • Get length: stringname.length
    • Get substring: stringname.substring(startingPosition, numberOfCharacters)
    • Convert cases: stringname.upper, stringname.lower
    • Find position: stringname.index("character")
  • How do you get the leftmost four characters of a string in OCR Exam Reference Language?

    Using stringname.left(4)
  • What does the ASC function do?
    Converts a character to its ASCII decimal number
  • What does the CHR function do?
    Converts an ASCII decimal number to its corresponding character