Alex & Jordan in Computer Science – Pseudocode / Programing Challenge 3

Alex is setting up their next storytelling game for game night, writing an epic adventure filled with monsters and magic, and characters that are inspired by their friendship group. Except Alex is stuck. Naming the characters is really hard, so he turns to an algorithm to help devise a method for naming them. They plan to create the names by merging parts of their friends’ real names, using a bit of coding magic to turn them into something new.

Your Task: Crafting Character Names

Alex presents you with a challenge of strings: write a program that

  • generates character names for each of their friends.
  • Names are created by:
    • combining the first three letters of their first name and last three letters of their surname to create the forename
    • combining the first two letters of their last name with a random ending of “ill”, “tal”, or “tye”
  • Output the created name for each friend along with their original name.

Friend’s Names:

First NameLast Name
AriaPatel
LiamO’Connor
MeiZhang
CarlosRivera
FatimaAl-Farsi
EthanJohnson
SofiaRodriguez
JaydenKim

If you’re trying out your code in Python, you can create your code using the editor below. To save your code, click the three bars on the left & select “Download”.

Answers

Click To See Pseudocode Answer

The answer below isn’t the only solution to this problem, but is one solution.

DECLARE firstNames : ARRAY OF STRING // for the whole answer this is 8 names
DECLARE lastNames : ARRAY OF STRING
DECLARE i, newName, newLastName : STRING

firstNames ← ["Aria", "Liam", "Mei"...]
lastNames ← ["Patel", "O'Connor", "Zhang"...]
ending ← ["ill", "tal", "tye"]

FOR i ← 0 TO LENGTH(firstNames) - 1 DO
    newName ← SUBSTRING(firstNames[i], 1, 3) + SUBSTRING(lastNames[i], LENGTH(lastNames[i]) - 2, 3)
    end ← ROUND(RANDOM() * LENGTH(ending)-1,0)
    newLastName ← SUBSTRING(lastNames[i], 1, 2) + ending[end]
    OUTPUT firstNames[i] + " " + lastNames[i] + " is now: " + newName + " " + newLastName
NEXT i

Markdown
Click To See OCR Reference Language Answer

The answer below isn’t the only solution to this problem, but is one solution.

array firstNames[3] of STRING // for the whole answer this is 8 names
array lastNames[3] of STRING

firstNames = ["Aria", "Liam", "Mei"]  
lastNames = ["Patel", "O'Connor", "Zhang"] 
ending = ["ill", "tal", "tye"]


for i = 0 TO firstNames.length -1 do
    
    newName = firstNames[i].left(3) + lastNames[i].right(3)     
    end_index = random(0,ending.length -1)  
    newLastName = lastNames[i].left(2) + ending[end_index]    

    print(firstNames[i], " ", lastNames[i], " is now: ",newName, " ", newLastName) 
Markdown
Click To See Python Answer

The answer below isn’t the only solution to this problem, but is one solution.

import random

# Declare the arrays of strings
firstNames = ["Aria", "Liam", "Mei"]  
lastNames = ["Patel", "O'Connor", "Zhang"] 
ending = ["ill", "tal", "tye"]


for i in range(len(firstNames)):
    # this uses slicing to get the substrings of each name
    newName = firstNames[i][:3] + lastNames[i][-3:] 
    
    end_index = round(random.random() * (len(ending) - 1))
  
    newLastName = lastNames[i][:2] + ending[end_index]
    

    print(firstNames[i], " ", lastNames[i], " is now: ",newName, " ", newLastName) 
Python

To study with me, you can join me on my iGCSE/GCSE Computer Science, iMedia Games Design, or A Level Computer Science courses.

Alex & Jordan Design An Adventure - The Ultimate iGCSE Computer Science Guide

The practice questions here are extra questions linked to my Pseudocode study book, “Alex & Jordan Design An Adventure” published in May 2024.

The book includes 20 coding problems to solve in pseudocode alongside answers with step by step explanations of how the pseudocode answer solves the problem and what each part means.

There are two editions of the book which follow the pseudocode in the Cambridge iGCSE & AQA GCSE Computer Science specifications, and OCR Reference Language for GCSE Computer Science.

Did you find this helpful?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this.

I'm sorry that this wasn't very useful for you!

Help me to improve this!

Tell me how I can improve this?