6.5 Developing Algorithms Using Pseudocode Flashcards
Less tham
<=
Less rhan or equal to
>
Greater than
> =
Gretaer than or equal to
==
Equal to
=
Assignment
!=
Not equal to
*
Multiply
Exponent
+
Addition (with int or float)
Concatenation (with strings)
If
Else if
Else
Branching
Switch case default
Branch depending on case
input(;
Get user inout
print()
Output to the user
for
Repeat a process for a set number of times
while
Repeaet while a condition is true
do untill
Do a loop untill a condition is true
str()
Cast to string
int()
Cast to integer
INTEGER
Whole number
Eg: 1, 2, 3, 4
REAL or FLOAT or DOUBLE
A number with a decimal point
Eg: 1.1, 1.2, 1.3, 1.4
BOOLEAN
Either True or False
CHARACTER
A single alphabetic or numeric character
Eg: ‘A’, ‘@’
STRING
A sequence of one or more characters
LIST or ARRAY
A container that conrain more data
Eg: [‘eggs’, ‘are’, ‘good’]
DICTIONARY
Key value pairs
Eg: {‘name’: marc, ‘age’: 14}
Give some boolean operators
> >= < <= == !=
100 > 10^2
False
n^2 == n*n
True
Pseudocode
Structurd english for descriving algorithms
Use of pseudocode
Allows a programmer to focus on the logic of the algorithm without being dristracted by syntax
Sequence
The statements are executed one by one, in the order they are written
Selection
The nest statement to be executed depends on whether the condition being tested is TRUE or FALSE
Switch/case
Used if there are several options to be tested
Assign a integer 5 to the variable x
x = 5
Assign an input for a person’s username to a variable called y
y = input(“What is your name? “)
Iteration
Repetition
Give examples of functions that use iteration
For
While
Do untill
Write a program that loops from 0 to 6 and prints out those numbers using iteration
for i in range(0, 7):
print(i)
Write a program that keeps asking for a password if its incorrect
password = input(“Enter password”)
while password != “secret”:
print(“incorrect password”)
password = input(“Enter password”)
Write a program that keeps asking for a password if its incorrect using a do untill loop
do:
password = input(“Enter password”)
until password == “secret”
print(“correct password”)