2.2 Programming techniques Flashcards
How to change case of variable
Pseudocode:
* Variable.upper/lower
Python:
* Variable.upper/lower()
How to find length of a variable
Pseudocode:
* Variable.length
Python:
* len(Variable)
How to convert something to ASCII
Pseudocode:
* ASC(A)
Python:
* ord(“A”)
How to convert ASCII to letter
Pseudocode:
* CHR(97)
Python:
* chr(97)
File handling
Open file
Pseudocode:
file = open(“fruit.txt”)
Python:
file = open(“fruit.txt”,”r”)
File Handling
Close file
file.close()
File handling
Readline
file.readline()
File handling
Writeline
Psuedocode:
file.writeline(“Oranges”)
Python:
file.write(“Oranges”)
File handling
New file
Pseudocode:
newFile(“Shopping.txt”)
Python:
file = open(“shopping.txt”,”w”)
Fields and records
Fields define the columns in a table, specifying what kind of data can be stored in each column.
Records represent the rows in a table, each row containing data for a specific instance of the entity being stored.
Functions vs procedures
a function returns a value, while a procedure does not
procedures could be printing something
Random numbers
Pseudocode:
number = random(1,10)
Python:
import random
number = random.randint(1,10)