programming constructs Flashcards

1
Q

Sequence

A

Code is executed ​line-by-line​, from top to bottom.

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

Branching

A

A certain block of code is run ​if a specific condition is met​, using IF statements. This is also known as ‘selection’.

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

Iteration

A

A block of code is executed a ​certain number of times​ or​ while a condition is met​. Iteration uses FOR, WHILE or REPEAT UNTIL loops.

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

iteration can be

count controlled-

A

for loop
~~~
for count in range (0,10):
print (“hi there”)
~~~

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

iteration can be

condition controlled example

A

while loop
~~~
import random
randomNumber=random.randint(0,10)
player guess = input(“which number am i thinking of”)
while int (playerGuess) != int(randomNumber):
playerGuess=input (“which number am i thinking of?”)
print (“you win”)
~~~

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

nest instruction example

while/if

A
import random
playerResponse=input ("would u like to play a game?")
while playerResponse == 'yes'
    randomNumber = random.randint(0,10)
    playerGuess == radnomNumber:
		if playerGuess == randomNumber:
		   print ("you win")
		elif int (playerGuess)> int (randomNumber):
		   print ("ur guess is too high")
	  elif int (playerGuess)< int (randomNumbeer):
		   print ("ur guess is too low")
			 
player response = input("would you like to play a game")
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

IF statement code

A
import random 
randomNumber=random.randint(0,10)
if playerGuess== randomNumber:
        print ("you win")
print ("thanks for playing")
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

IF ELSE statement code

A
import random
randomNumber = ra som.randint (0,10)
playerGuess= input (which number am i thinking of")
if playerGuess == random number:
    print ("you win")
else:
     print ("you lose")
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

ELIF statement code

A
import random
randomNumber= random.randint (0,10)
playerGuess=input("which number am i thinking of")
if playerGuess == randomNumber:
      print("you win")
ELIF  int(playerGuess) > (randomNumber:
      print("too high")
ELIF int(playerGiess)< (randomNumber:
       print("too low:)
			 
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

while loops

A

used to repeat an instruction(or sequence of instructions) and loop until a condition is met

condition controlled loop

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

for loop

A

execute an instruction (or squence of instructions) a set.number of times
we creaste a variable called ‘count’ and set it to zero. every time the code inside the loop is executed count is incremented by 1.
when count reaches the value set by the programmer, the computer stops ececuted the code inside the loop and moves to the next instruction outside the loop.

count controlled

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

nesting

A

when you place one construct within of another.

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