Your friend is writing a fantasy novel set in the mythical land of Aetheria, but they're struggling to create character names. Help them by building a name generator!
Below, you'll find:
first_names
suitable for Aetherian characterslast_names
suitable for Aetherian charactersrandint
function to help you select random namesWrite a function random_name()
that returns a randomly generated full name.
Example:
print(random_name())
# Output: "Thranduil Starfire"
Write a function random_party(party_size)
that generates multiple unique character names and returns them as a grammatically correct string.
Examples:
print(random_party(1))
# Output: "Thranduil Brightblade"
print(random_party(2))
# Output: "Gandalf Ironfist and Celeborn Starfire"
print(random_party(3))
# Output: "Thranduil Brightblade, Gandalf Ironfist, and Celeborn Starfire"
Requirements:
randint
¶randint(a, b) # Returns random integer from a to b (inclusive)
# Example: randint(0, 9) could return any number from 0 to 9
result = ""
for i in range(3):
result += str(i)
print(result) # "012"
Remember: if a list has 10 items, valid indices are 0-9!
from random import randint
first_names = [
"Arwen",
"Elrond",
"Galadriel",
"Legolas",
"Thranduil",
"Eowyn",
"Boromir",
"Faramir",
"Gandalf",
"Celeborn",
]
last_names = [
"Stormrider",
"Shadowhunter",
"Moonwhisper",
"Nightshade",
"Dragonbane",
"Ironfist",
"Brightblade",
"Windwalker",
"Starfire",
"the Bard",
]
def random_name():
first_name_idx = randint(0, len(first_names) - 1)
last_name_idx = randint(0, len(last_names) - 1)
first_name = first_names[first_name_idx]
last_name = last_names[last_name_idx]
return f"{first_name} {last_name}"
def random_party(party_size):
party = []
while len(party) < party_size:
new_name = random_name()
if new_name not in party:
party.append(new_name)
party_name = ""
for i in range(len(party)):
name = party[i]
if i == 0:
party_name += name
elif i == len(party) - 1:
party_name += ", and " + name
else:
party_name += ", " + name
return party_name
# Example Usage
print(f"{random_name()} entered the tavern where they met {random_name()} the tavern keep")
print(f"{random_party(3)} approached the evil {random_name()}")
Boromir Stormrider entered the tavern where they met Galadriel the Bard the tavern keep Gandalf Nightshade, Thranduil Moonwhisper, Elrond Nightshade, Legolas Shadowhunter, and Legolas Starfire approached the evil Galadriel Brightblade Thranduil Brightblade, Legolas Starfire, and Gandalf Brightblade