7.2 Sequence And Selection Flashcards
What are 3 basic control structures used in programming?
Sequence, selection and iteration
Sequence
The statements are executed one by one in the order they are written
Selection
Declared by an if statement. If the statement is true than the code executed will be the one with the true value.
==
Equals to
!=
Not equals to
>
Greater than
Less than
> =
Greater than or equal to
<=
Less than or equal to
Nested if statements are…
If statements inside if statements
AND
Returns true if both conditions are true
OR
Returns true if either of the conditions are true
NOT
The opposite of the given input (true -> false, false-> true)
Switch/case statement is used when…
A selection is to be made from several alternatives, for example when choosing from a menu
How could you simulate a dice throw with the ‘random’ module?
import random
throw = random.randint(1, 7) #1 because we want it to start on 1 and 7 because python #counts to the number before the inputted number