1/29
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Programming
Telling a computer what to do
Giving the computer instructions to carry out
Syntax for print
print(‘Text’)
print(“Text”)
Starts in single: must end in single
Starts in double: must end in double
Types of errors
Syntax
Logical
Runtime
Syntax Errors
Errors in how the code is written
Doesn't adhere to the rules
Logical Errors
Also called semantic errors
Does not output what was intended
Error in calculation/process
Runtime
Cause the program to terminate
Examples
dividing by 0
Infinite loop
Incorrect input by the user
Variable
A value that is given a name and can be changed
String
A piece of text
An integer
A whole number
Floating-Point Number
A number with a decimal point
Syntax for input
Name=input(“Prompt”)
Syntax for integer input
Integer=int(input(“Prompt”))
Arithmetic Operation Syntax
answer=num1+num2
To perform a math operation, convert input into
int() or float()
Input
Read from the keyboard
Display to the screen
If
Check a condition to see which operations to perform
=
Assign a value to a variable
While
Perform actions repeatedly
Syntax for Lists
List_name = [“item1”, “item2”, “item3”]
Lists
A type of data structure
Data Structure
Data structures are organised collections of data
Data is organised in ___________________
A sequence, with each item having a unique index
Index
Tells you the position of each item in a list
IndexError
This occurs when an index number that doesn't exist gets called
Position
Index + 1
Syntax to find number of items on a list
len(name of list)
Syntax to find the index of a list item
number = listname.index(“object”)
Iterative Structure
Used when a program needs to repeat a block of code
Needed when a program needs to repeat actions
While Loop
Repeats actions while a condition is true