Programming Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

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

A

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)

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

What is a data type?

A

It is a way of classifying a value so the programming language knows how to interpret the value

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

What is a count controlled loop?

A

Used when the number of iterations to occur is already known
We know how many times we want to execute the loop

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

What is a variable?

A

A value which is stored inside the computers memory.

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

What is a for loop? Give example

A

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)

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

What is a while loop give example?

A

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

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

Example of pseudocode in python

A

Endif
Endwhile

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

Rule of pseudocode

A

If the code is pseudocode you dont put a data type before any value because it doesnt need it

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

Code asks user for phone number and length needs to be over 6 letters and under 12

A

Number=int(input(“What is your phone number”))
If len(number) == 0:
Print(“Invalid”)
Elif len(number) >6 AND <12:
Print(“Thank you”)
Endif

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

What is a variable?

A

A value stored within a reserved memory location in the computer

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

Difference between a variable and a constant?

A

A constant cant change at all whilst a variable can

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

What is an array?

A

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

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

What is a list?

A

A dynamic structure which can contain elements of different types. Ordered and not fixed in size

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

What is a 2 dimensional array?

A

A collection of elements arranged in a table like structure wth rows and columns

An array inside an array

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

What does def mean?

A

Short for define it defines the function

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

Whats iterative testing?

A

Testing that is ongoing throughout it the development process whilst the code is being written.

17
Q

What is final testing?

A

When the development of the code is fine it is tested

18
Q

Wat is a syntax error?

A

An error where the code doesn’t meet the rules of the programming language