Pseudocode/Coding Syntax Flashcards
How to divide:
5 divided by 2 to give 2.5
in pseudo and Python
both use:
5/2 = 2.5
It returns a float
How to divide for quotient:
5 divided by 2 to give 2
Python:
5//2 = 2
Pseudocode:
5DIV2 = 2
How to divide for remainder:
5 divided by 2 to give 1
Python:
5%2 = 1
Pseudocode:
5MOD2 = 1
Input a name in pseudocode and assign it to a variable
MyName = input(“Enter name: “)
Output in pseudocode
print(…)
counter controlled loops in pseudocode
for i = 0 to 9 step 2
print(“Loop”)
next i
This prints Loop 5 times
condition controlled pseudocode
while
endwhile
or
do
STATEMENTS
until
selection in pseudocode
if… then
elseif…then
else
endif
or
switch VARIABLE:
case CONDITION:
default:
endswitch
finding string length in Python and pseudocode
Python: len(subject)
Pseudocode: subject.length
phrase = “Hello World”
Make a substring “Hello”
Pseudocode:
phrase.substring(0, 5)
0 = first index, 0 indexed
5 = length of substring
Python:
phrase[0:5], does not print the 5th indexed character
ASCII value for 0
48
ASCII value for “A”
65
ASCII value for “a”
97
convert A to its ASCII value
Python: ord(“A”) = 65
Pseudo: ASC(“A”) = 65
convert 97 in ASCII to its character
Python: chr(97) = “a”
Pseudo: CHR(97) = “a”
Write a program that appends “Banana” to an existing file fruits.txt, outputs it and closes the file in pseudocode and Python
Pseudocode:
f = open(“fruits.txt”)
f.writeLine(“Banana”)
f.readline()
f.close()
Python:
with open(“fruits.txt”, “a”) as file:
file.write(“Banana”)
with open(“fruits.txt”, “r”) as file:
print(file.read())
Print all lines in a file in pseudocode
while NOT myFile.endOfFile()
print(myFile.readLine())
endwhile
Create a new file in pseudocode
newFile(“myText.txt”)
Write to a file in Python
with open(“example.txt”, “w”) as file
file.write(“Hello World\n”)
What does \n mean?
Moves written text to a new line.
How to convert to upper/lowercase in pseudocode and Python
pseudocode: string.upper
Python: string.upper()
How do you find the 4 rightmost characters in a string in pseudocode and Python?
pseudocode:
subject = “Computer Science”
answer = subject.right(4)
Python:
answer = subject[-4:]
How to concatenate in pseudocode and Python
Use + to concatenate strings
How to make a new file in pseudocode and Python
Pseudocode
newFile(“fruits.txt”)
Python:
with open(“newfile.txt”, “w”) as file:
file.write(“Hello, this is a new file!”)
How to make a new array in pseudocode and Python
Pseudocode
array colors[“a”, “b”]
Python
colors = [“a”, “b”]