programming (theres nothing PRO about it.) Flashcards
describe what is meant by ‘data type’
A classification that specifies the type of data a variable or constant can hold (e.g., integer, real, Boolean).
what is an integer
a whole number, positive or negative
what is a real number
a number with a decimal point
what is boolean
a data type that represents true or false values
what is a character
a single letter, digit or symbol
what is a string
a sequence of characters
what is a variable
a named location in memory that stores a value that can change in a program
what is a constant
a names location in memory that stores a value that doesn’t change in a program
what is iteration
the repetition of a block of code
e.g. for loops (definite) or while loops (indefinite)
what is selection
making decisions in code using if, else if and else statements to execute specific code paths
what is a subroutine
a reusable block of code that performs a specific task
eg functions or procedures
what is count controlled iteration
A loop that repeats a set number of times
e.g
for i in range(5):
what is a condition controlled iteration
a loop that repeats until a condition is met
e.g while x<10:
what is a nested structure
code blocks inside other code blocks such as a loop inside another loop or an if inside a for
why use meaningful identifiers
make code easier to understand by clearly describing the purpose of variances constants and subroutines
how to accept keyboard input in python
name= input(“Enter your name: “)
how to display output on the screen
print (“Hello, World!”)
how to read from a text file
with open(“file.txt”, “r”) as file:
data = file.read()
how to write a text file
with open(“file.txt”, “w”) as file:
file.write(“Hello!”)
string operations: length
len(“Hello”) # Returns 5
string operations: position
“Hello”.index(“1”) #returns e
string operations: sub string
Returns “ell”
“hello” [1:4]
string operations: concatenation
“Hello” + “ World” # Returns “Hello World”
casting one data type to another
int(“5”) # Converts “5” to 5
str(10) # Converts 10 to “10”