Menu

Pseudocode

Records and Strings

A record groups related data items under one identifier. The items inside it are called fields, and each field can hold a different type, because a record describes one whole thing — a player, a product, a hospital patient — rather than a list of matching values.

FieldTypeExample value
playerNamestring"Nadia"
shirtNumberinteger11
averageSpeedreal7.4

Keeping these three values inside one record means the whole record can be stored, moved and printed as a single item, and the fields stay together so they cannot be mixed up with another player's data. To hold a whole team you use an array of records: one element per player, and a FOR loop that visits each element and reads its fields. A record is not a two-dimensional array — its fields may be different types and are reached by name, not by a row and column position.

A record called playerRecord with fields playerName (string, "Nadia"), shirtNumber (integer, 11) and averageSpeed (real, 7.4), beside an array of records numbered 0, 1, 2 with one player record in each element.

Strings

A string is a one-dimensional sequence of characters, used for any text: a word, a postcode, a password. len() gives the number of characters it holds.

Because a string is a sequence, a FOR loop can process it one character at a time — counting something, checking a code follows a pattern, or building a new string from the pieces. This example counts how many vowels a word contains.

word = input("Enter a word: ")
vowels = 0
for letter in word:
    if letter == "a" or letter == "e" or letter == "i" or letter == "o" or letter == "u":
        vowels = vowels + 1
print("Vowels: " + str(vowels))

Output when the user types pineapple:

Enter a word: pineapple
Vowels: 4

The IF condition compares each character with lowercase vowels only, so a word typed in capitals would score nothing.

Practise this