programming (theres nothing PRO about it.) Flashcards

1
Q

describe what is meant by ‘data type’

A

A classification that specifies the type of data a variable or constant can hold (e.g., integer, real, Boolean).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what is an integer

A

a whole number, positive or negative

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what is a real number

A

a number with a decimal point

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what is boolean

A

a data type that represents true or false values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what is a character

A

a single letter, digit or symbol

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what is a string

A

a sequence of characters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what is a variable

A

a named location in memory that stores a value that can change in a program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what is a constant

A

a names location in memory that stores a value that doesn’t change in a program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what is iteration

A

the repetition of a block of code
e.g. for loops (definite) or while loops (indefinite)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what is selection

A

making decisions in code using if, else if and else statements to execute specific code paths

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what is a subroutine

A

a reusable block of code that performs a specific task
eg functions or procedures

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

what is count controlled iteration

A

A loop that repeats a set number of times
e.g
for i in range(5):

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what is a condition controlled iteration

A

a loop that repeats until a condition is met
e.g while x<10:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

what is a nested structure

A

code blocks inside other code blocks such as a loop inside another loop or an if inside a for

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

why use meaningful identifiers

A

make code easier to understand by clearly describing the purpose of variances constants and subroutines

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

how to accept keyboard input in python

A

name= input(“Enter your name: “)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

how to display output on the screen

A

print (“Hello, World!”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

how to read from a text file

A

with open(“file.txt”, “r”) as file:
data = file.read()

19
Q

how to write a text file

A

with open(“file.txt”, “w”) as file:
file.write(“Hello!”)

20
Q

string operations: length

A

len(“Hello”) # Returns 5

21
Q

string operations: position

A

“Hello”.index(“1”) #returns e

22
Q

string operations: sub string

A

Returns “ell”

“hello” [1:4]

23
Q

string operations: concatenation

A

“Hello” + “ World” # Returns “Hello World”

24
Q

casting one data type to another

A

int(“5”) # Converts “5” to 5
str(10) # Converts 10 to “10”

25
advantages of subroutines
avoid code repetition make program easier to read and maintain simplify debugging
26
what is a parameter
a variable passed into a subroutine to provide input or receive output
27
How to define and use a subroutine in Python? python Copy code
def greet(name): print(f"Hello, {name}!") greet("Alice")
28
arithmetic operations in python
x + y # Addition x - y # Subtraction x * y # Multiplication x / y # Division
29
relational operations
x < y, x > y, x == y, x != y
30
logical operations
AND: True if both conditions are True. python True and False # Returns False OR: True if at least one condition is True. python True or False # Returns True NOT: Inverts the Boolean value. python not True # Returns False
31
what is a data structure
a way of organising data for efficient access and modification (eg arrays, records)
32
what is a one dimensional array
a list of items stored in a single row
33
what is a two dimensional array
a table like structure where data is stored in rows and columns e.g., [[1, 2], [3, 4]].
34
what is a record
a collection of fields, each holding a value, often representing a single entity
35
use of records
student = {"name": "Alice", "age": 16, "grade": "A"} print(student["name"]) # Outputs: Alice
36
difference between global and local variables
global - accessible throughout the program local- accessible only within a specific subroutine or block
37
what is a validation routine
code that checks used input meets certain criteria (e.g., not empty, within range).
38
what is an authentication routine
code that verifies a users identity e.g., matching username and password.
39
Types of test data
Normal: Typical inputs that should work. Boundary: Values at the edge of acceptable input. Erroneous: Invalid inputs to check error handling.
40
low level vs high level languages
low level- closer to machine code, harder to read (eg assembly) high level- easier to read and write (eg python)
41
what is an interpreter
translates and runs code line by line
42
what is a compiler
translates the entire program into machine code before running
43
what is an assembler
translates assembly language into machine code