Back to 课程

Computer Science GCES EDEXCEL

0% Complete
0/0 Steps
  1. Decomposition And Abstraction Edexcel
    2 主题
  2. Algorithms Edexcel
    11 主题
  3. Truth Tables Edexcel
    3 主题
  4. Binary Edexcel
    6 主题
  5. Data Representation Edexcel
    4 主题
  6. Data Storage And Compression Edexcel
    2 主题
  7. Hardware Edexcel
    5 主题
  8. Software Edexcel
    3 主题
  9. Programming Languages Edexcel
    2 主题
  10. Networks Edexcel
    7 主题
  11. Network Security Edexcel
    2 主题
  12. Environmental Issues Edexcel
    1 主题
  13. Ethical And Legal Issues Edexcel
    3 主题
  14. Cybersecurity Edexcel
    2 主题
  15. Develop Code Edexcel
    6 主题
  16. Constructs Edexcel
    4 主题
  17. Data Types And Data Structures Edexcel
    5 主题
  18. Operators Edexcel
    1 主题
  19. Subprograms Edexcel
    2 主题
课 Progress
0% Complete

Exam code:1CP2

Constants, Variables, Initialisation & Assignment

Constants

  • A constant is an identifier set once in the lifetime of a program

  • Constants are named in all uppercase characters

  • Constants aid the readability and maintainability

  • If a constant needs to be changed, it should only need to be altered in one place in the whole program

Python examples

PI = 3.142

VAT = 0.20

PASSWORD = "letmein"

Variables

  • A variable is an identifier that can change in the lifetime of a program

  • Variables are named in lowercase characters unless combining multiple words

  • A variable can be associated a datatype when it is declared

  • When a variable is declared, memory is allocated based on the data type indicated

Python examples

score = int() # whole number

cost = float() # decimal number

light = bool() # data can only have one or two values

Initialisation & assignment

  • A variable can be initialised with a value

  • The assignment operator = is used to set or change the value of a variable

Python examples

score = 10 # Initialise with a value

cost = 9.50 # Initialise with a value

count = count + 1 # Adds one to the current value of count

Inputs & Outputs

Inputs

  • The input() function is used to capture an input from the user

  • All inputs default to strings and may need converting to the required data type in the program

Python examples

surname = input("Enter your surname: ")

examScore = int(input("Enter your exam score: "))

height = float(input("Enter height: "))

Outputs

  • The print() function is used to output to the screen

Python examples

print("Hello world")

examScore = 90

print(examScore)

print("Exam score: ", examScore)

  • An output can be formatted to the users needs using string formatting {}

Python examples

print("{:.2f}".format (price)) # Displays a currency value to two decimal places

print(f"Pi approximation: {pi_approx}") # Displays a variable formatted as a string with a label

Responses

您的邮箱地址不会被公开。 必填项已用 * 标注