Pseudocode/Coding Syntax Flashcards

1
Q

How to divide:
5 divided by 2 to give 2.5
in pseudo and Python

A

both use:
5/2 = 2.5
It returns a float

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

How to divide for quotient:
5 divided by 2 to give 2

A

Python:
5//2 = 2
Pseudocode:
5DIV2 = 2

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

How to divide for remainder:
5 divided by 2 to give 1

A

Python:
5%2 = 1
Pseudocode:
5MOD2 = 1

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

Input a name in pseudocode and assign it to a variable

A

MyName = input(“Enter name: “)

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

Output in pseudocode

A

print(…)

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

counter controlled loops in pseudocode

A

for i = 0 to 9 step 2
print(“Loop”)
next i
This prints Loop 5 times

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

condition controlled pseudocode

A

while
endwhile

or

do
STATEMENTS
until

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

selection in pseudocode

A

if… then
elseif…then
else
endif

or

switch VARIABLE:
case CONDITION:
default:
endswitch

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

finding string length in Python and pseudocode

A

Python: len(subject)
Pseudocode: subject.length

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

phrase = “Hello World”
Make a substring “Hello”

A

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

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

ASCII value for 0

A

48

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

ASCII value for “A”

A

65

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

ASCII value for “a”

A

97

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

convert A to its ASCII value

A

Python: ord(“A”) = 65
Pseudo: ASC(“A”) = 65

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

convert 97 in ASCII to its character

A

Python: chr(97) = “a”
Pseudo: CHR(97) = “a”

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

Write a program that appends “Banana” to an existing file fruits.txt, outputs it and closes the file in pseudocode and Python

A

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())

17
Q

Print all lines in a file in pseudocode

A

while NOT myFile.endOfFile()
print(myFile.readLine())
endwhile

18
Q

Create a new file in pseudocode

A

newFile(“myText.txt”)

19
Q

Write to a file in Python

A

with open(“example.txt”, “w”) as file
file.write(“Hello World\n”)

20
Q

What does \n mean?

A

Moves written text to a new line.

21
Q

How to convert to upper/lowercase in pseudocode and Python

A

pseudocode: string.upper
Python: string.upper()

22
Q

How do you find the 4 rightmost characters in a string in pseudocode and Python?

A

pseudocode:
subject = “Computer Science”
answer = subject.right(4)
Python:
answer = subject[-4:]

23
Q

How to concatenate in pseudocode and Python

A

Use + to concatenate strings

24
Q

How to make a new file in pseudocode and Python

A

Pseudocode
newFile(“fruits.txt”)
Python:
with open(“newfile.txt”, “w”) as file:
file.write(“Hello, this is a new file!”)

25
Q

How to make a new array in pseudocode and Python

A

Pseudocode
array colors[“a”, “b”]
Python
colors = [“a”, “b”]