Programming Flashcards
Write a program that prints fizz if the number is a multiple of 3, buzz if its a multiple of 5 and both if its a mult of 3 and 5
for counter in range (1,101):
if counter%3 == 0 and counter%5 == 0:
print(‘FizzBuzz’)
if counter%3 == 0:
print(“Fizz”)
if counter % 5 == 0:
print(“Buzz”)
else:
print(counter)
What is a data type?
It is a way of classifying a value so the programming language knows how to interpret the value
What is a count controlled loop?
Used when the number of iterations to occur is already known
We know how many times we want to execute the loop
What is a variable?
A value which is stored inside the computers memory.
What is a for loop? Give example
A block of code that repeats for a limited amount of times. Stops when condition is proven true.
E.g, numbers = [1,2,3,4,9,16]
B=[]
For i in numbers:
B.append(i**2)
Print(b)
What is a while loop give example?
A while loop is a block of code which repeats until the condition is proven false.
X = 5
While x < 5:
X = x+1
Print(“John”)
Or
Num = 1
While True:
Print (“John”)
Num = num+1
If num == 5:
Break
Example of pseudocode in python
Endif
Endwhile
Rule of pseudocode
If the code is pseudocode you dont put a data type before any value because it doesnt need it
Code asks user for phone number and length needs to be over 6 letters and under 12
Number=int(input(“What is your phone number”))
If len(number) == 0:
Print(“Invalid”)
Elif len(number) >6 AND <12:
Print(“Thank you”)
Endif
What is a variable?
A value stored within a reserved memory location in the computer
Difference between a variable and a constant?
A constant cant change at all whilst a variable can
What is an array?
A static structure which constains items of the same data type. A series of memory locations which contains a single item of data.. ordered and fixed in size
What is a list?
A dynamic structure which can contain elements of different types. Ordered and not fixed in size
What is a 2 dimensional array?
A collection of elements arranged in a table like structure wth rows and columns
An array inside an array
What does def mean?
Short for define it defines the function