我正在做一个简单的漫长的d&d娱乐,一切都很好,直到我选择我的性别作为男性。然后 2 个字符出来而不是一个



一切正常,除了男性性别打印。当它被选为女性时,屏幕上只会显示所选种族的一个名字和姓氏。但是当我选择男性时,有两个不同的角色名称。首先是我选择的种族的男性,然后在另一排是随机的。我真的不知道哪里出了问题,因为男性和女性的代码非常相似,我已经检查了错误。

import random
#https://www.dndbeyond.com/races
#DM introduction
print(
f"Hi, my name is Lones and I will be your Dungeon Master today. I will walk you trough the simple edition of Dungeons and Dragons with different twists and rules which differ from the original. I hope you'll enjoy your stay."
)
print(f"𝘤𝘭𝘪𝘤𝘬 𝘦𝘯𝘵𝘦𝘳 𝘸𝘩𝘦𝘯 𝘺𝘰𝘶'𝘳𝘦 𝘥𝘰𝘯𝘦 𝘳𝘦𝘢𝘥𝘪𝘯𝘨")
print(f"------------------------------------")
input()
#Character Introduction
print(
f"There are 9 races between you can chose for now. I will provide you with some info on their background and strengths so that you can understand them. This game is going to be decided by luck / by roling the dice. I will provide you with the whole list after introductions in case you forgot the races.")
print(f"𝘤𝘭𝘪𝘤𝘬 𝘦𝘯𝘵𝘦𝘳 𝘸𝘩𝘦𝘯 𝘺𝘰𝘶'𝘳𝘦 𝘥𝘰𝘯𝘦 𝘳𝘦𝘢𝘥𝘪𝘯𝘨")
print(f"------------------------------------")
input()
#1.Dragoborn
print(f"1. Dragonborn -->")
print(f"𝘤𝘭𝘪𝘤𝘬 𝘦𝘯𝘵𝘦𝘳 𝘸𝘩𝘦𝘯 𝘺𝘰𝘶'𝘳𝘦 𝘥𝘰𝘯𝘦 𝘳𝘦𝘢𝘥𝘪𝘯𝘨")
print(f"----------------")
input()
print(
f"Born of dragons, as their name proclaims, the dragonborn walk proudly through a world that greets them with fearful incomprehension. Shaped by draconic gods or the dragons themselves, dragonborn originally hatched from dragon eggs as a unique race, combining the best attributes of dragons and humanoids. "
)
print(f"-Strength + 2, Charisma + 1")
print(
f"-Damage resistance to the damage type associated with draconic ancestry")
print(f"𝘤𝘭𝘪𝘤𝘬 𝘦𝘯𝘵𝘦𝘳 𝘸𝘩𝘦𝘯 𝘺𝘰𝘶'𝘳𝘦 𝘥𝘰𝘯𝘦 𝘳𝘦𝘢𝘥𝘪𝘯𝘨")
print(f"------------------------------------")
input()
#2.Dwarf
print(f"2. Dwarf -->")
print(f"𝘤𝘭𝘪𝘤𝘬 𝘦𝘯𝘵𝘦𝘳 𝘸𝘩𝘦𝘯 𝘺𝘰𝘶'𝘳𝘦 𝘥𝘰𝘯𝘦 𝘳𝘦𝘢𝘥𝘪𝘯𝘨")
print(f"----------------")
input()
print(
f"Kingdoms rich in ancient grandeur, halls carved into the roots of mountains, the echoing of picks and hammers in deep mines and blazing forges, a commitment to clan and tradition, and a burning hatred of goblins and orcs—these common threads unite all dwarves. "
)
print(f"-Constitution + 2, Wisdom + 1")
print(f"-Poison resistance")
print(f"𝘤𝘭𝘪𝘤𝘬 𝘦𝘯𝘵𝘦𝘳 𝘸𝘩𝘦𝘯 𝘺𝘰𝘶'𝘳𝘦 𝘥𝘰𝘯𝘦 𝘳𝘦𝘢𝘥𝘪𝘯𝘨")
print(f"------------------------------------")
input()
#3.Elf
print(f"3. Elf -->")
print(f"𝘤𝘭𝘪𝘤𝘬 𝘦𝘯𝘵𝘦𝘳 𝘸𝘩𝘦𝘯 𝘺𝘰𝘶'𝘳𝘦 𝘥𝘰𝘯𝘦 𝘳𝘦𝘢𝘥𝘪𝘯𝘨")
print(f"----------------")
input()
print(
f"Elves are a magical people of otherworldly grace, living in the world but not entirely part of it. They live in places of ethereal beauty, in the midst of ancient forests or in silvery spires glittering with faerie light, where soft music drifts through the air and gentle fragrances waft on the breeze. "
)
print(f"-Dexterity + 2, Intelligence + 1")
print(f"-Perception skill")
print(f"𝘤𝘭𝘪𝘤𝘬 𝘦𝘯𝘵𝘦𝘳 𝘸𝘩𝘦𝘯 𝘺𝘰𝘶'𝘳𝘦 𝘥𝘰𝘯𝘦 𝘳𝘦𝘢𝘥𝘪𝘯𝘨")
print(f"------------------------------------")
input()
#4.Gnome
print(f"4. Gnome -->")
print(f"𝘤𝘭𝘪𝘤𝘬 𝘦𝘯𝘵𝘦𝘳 𝘸𝘩𝘦𝘯 𝘺𝘰𝘶'𝘳𝘦 𝘥𝘰𝘯𝘦 𝘳𝘦𝘢𝘥𝘪𝘯𝘨")
print(f"----------------")
input()
print(
f"A constant hum of busy activity pervades the warrens and neighborhoods where gnomes form their close-knit communities. Louder sounds punctuate the hum: a crunch of grinding gears here, a minor explosion there, a yelp of surprise or triumph, and especially bursts of laughter.  "
)
print(f"-Intelligence + 2, Dexterity + 1")
print(f"-Stone Camouflage")
print(f"𝘤𝘭𝘪𝘤𝘬 𝘦𝘯𝘵𝘦𝘳 𝘸𝘩𝘦𝘯 𝘺𝘰𝘶'𝘳𝘦 𝘥𝘰𝘯𝘦 𝘳𝘦𝘢𝘥𝘪𝘯𝘨")
print(f"------------------------------------")
input()
#5.Half-Elf
print(f"5. Half-Elf -->")
print(f"𝘤𝘭𝘪𝘤𝘬 𝘦𝘯𝘵𝘦𝘳 𝘸𝘩𝘦𝘯 𝘺𝘰𝘶'𝘳𝘦 𝘥𝘰𝘯𝘦 𝘳𝘦𝘢𝘥𝘪𝘯𝘨")
print(f"----------------")
input()
print(
f"Walking in two worlds but truly belonging to neither, half-elves combine what some say are the best qualities of their elf and human parents: human curiosity, inventiveness, and ambition tempered by the refined senses, love of nature, and artistic tastes of the elves. Some half-elves live among humans, set apart by their emotional and physical differences, watching friends and loved ones age while time barely touches them.  "
)
print(f"-Charisma + 2, two abilities scores of your choice + 1")
print(f"-You gain proficiency in two skills of your choice.")
print(f"𝘤𝘭𝘪𝘤𝘬 𝘦𝘯𝘵𝘦𝘳 𝘸𝘩𝘦𝘯 𝘺𝘰𝘶'𝘳𝘦 𝘥𝘰𝘯𝘦 𝘳𝘦𝘢𝘥𝘪𝘯𝘨")
print(f"------------------------------------")
input()
#6.Halfing
print(f"6. Halfing -->")
print(f"𝘤𝘭𝘪𝘤𝘬 𝘦𝘯𝘵𝘦𝘳 𝘸𝘩𝘦𝘯 𝘺𝘰𝘶'𝘳𝘦 𝘥𝘰𝘯𝘦 𝘳𝘦𝘢𝘥𝘪𝘯𝘨")
print(f"----------------")
input()
print(
f"The comforts of home are the goals of most halflings’ lives: a place to settle in peace and quiet, far from marauding monsters and clashing armies; a blazing fire and a generous meal; fine drink and fine conversation. Though some halflings live out their days in remote agricultural communities, others form nomadic bands that travel constantly, lured by the open road and the wide horizon to discover the wonders of new lands and peoples. "
)
print(f"-Dexterity + 2, Charisma + 1")
print(f"-Naturally Stealthy, Lucky and Brave")
print(f"𝘤𝘭𝘪𝘤𝘬 𝘦𝘯𝘵𝘦𝘳 𝘸𝘩𝘦𝘯 𝘺𝘰𝘶'𝘳𝘦 𝘥𝘰𝘯𝘦 𝘳𝘦𝘢𝘥𝘪𝘯𝘨")
print(f"------------------------------------")
input()
#7.Half-Orc
print(f"7. Half-Orc -->")
print(f"𝘤𝘭𝘪𝘤𝘬 𝘦𝘯𝘵𝘦𝘳 𝘸𝘩𝘦𝘯 𝘺𝘰𝘶'𝘳𝘦 𝘥𝘰𝘯𝘦 𝘳𝘦𝘢𝘥𝘪𝘯𝘨")
print(f"----------------")
input()
print(
f"Whether united under the leadership of a mighty warlock or having fought to a standstill after years of conflict, orc and human tribes sometimes form alliances, joining forces into a larger horde to the terror of civilized lands nearby. When these alliances are sealed by marriages, half-orcs are born.  "
)
print(f"-Strength + 2, Dexterity + 1")
print(f"-Intimidation skill")
print(f"𝘤𝘭𝘪𝘤𝘬 𝘦𝘯𝘵𝘦𝘳 𝘸𝘩𝘦𝘯 𝘺𝘰𝘶'𝘳𝘦 𝘥𝘰𝘯𝘦 𝘳𝘦𝘢𝘥𝘪𝘯𝘨")
print(f"------------------------------------")
input()
#8.Human
print(f"8. Human -->")
print(f"𝘤𝘭𝘪𝘤𝘬 𝘦𝘯𝘵𝘦𝘳 𝘸𝘩𝘦𝘯 𝘺𝘰𝘶'𝘳𝘦 𝘥𝘰𝘯𝘦 𝘳𝘦𝘢𝘥𝘪𝘯𝘨")
print(f"----------------")
input()
print(
f"In the reckonings of most worlds, humans are the youngest of the common races, late to arrive on the world scene and short-lived in comparison to dwarves, elves, and dragons. Perhaps it is because of their shorter lives that they strive to achieve as much as they can in the years they are given.  "
)
print(
f"-Each ability score + 1, you gain proficiency in one skill of your choice"
)
print(f"-Intimidation skill")
print(f"------------------------------------")
input()
#9.Tiefling
print(f"9. Tiefling -->")
print(f"𝘤𝘭𝘪𝘤𝘬 𝘦𝘯𝘵𝘦𝘳 𝘸𝘩𝘦𝘯 𝘺𝘰𝘶'𝘳𝘦 𝘥𝘰𝘯𝘦 𝘳𝘦𝘢𝘥𝘪𝘯𝘨")
print(f"----------------")
input()
print(
f"To be greeted with stares and whispers, to suffer violence and insult on the street, to see mistrust and fear in every eye: this is the lot of the tiefling. And to twist the knife, tieflings know that this is because a pact struck generations ago infused the essence of Asmodeus—overlord of the Nine Hells—into their bloodline.  "
)
print(f"Charisma + 2, Intelligence + 1")
print(f"-Intimidation skill")
print(f"-Fire Resistance")
print(f"------------------------------------")
input()
print(f"1. Dragonborn -->")
print(f"2. Dwarf -->")
print(f"3. Elf -->")
print(f"4. Gnome -->")
print(f"5. Half-Elf -->")
print(f"6. Halfing -->")
print(f"7. Half-Orc -->")
print(f"8. Human -->")
print(f"9. Tiefling -->")
print(f"----------------")
Dragonborn = 1
Dwarf = 2
Elf = 3
Gnome = 4
Half_Elf = 5
Halfing = 6
Half_Orc = 7
Human = 8
Tiefling = 9

input()
dice = random.randrange(1, 9)
dice1 = random.randrange(1, 9)

if (dice == Dragonborn):
print(f"You got Dragonborn")
elif (dice == Dwarf):
print(f"You got Dwarf")
elif (dice == Elf):
print(f"You got Elf")
elif (dice == Gnome):
print(f"You got Gnome")
elif (dice == Half_Elf):
print(f"You got Half-Elf")
elif (dice == Halfing):
print(f"You got Halfing")
elif (dice == Half_Orc):
print(f"You got Half-Orc")
elif (dice == Human):
print(f"You got Human")
elif (dice == Tiefling):
print(f"You got Tiefling")
print(f"----------------")
response = input(f"If you're happy by the choice of your dice type continue and if you aren't type reroll: ")
if(response == "continue"):
print(f"You wish to continue the game")
elif(response == "reroll"):
print(f"You wish to reroll the dice. This is your last roll this round.")
if (dice1 == Dragonborn):
print(f"You got Dragonborn")
elif (dice1 == Dwarf):
print(f"You got Dwarf")
elif (dice1 == Elf):
print(f"You got Elf")
elif (dice1 == Gnome):
print(f"You got Gnome")
elif (dice1 == Half_Elf):
print(f"You got Half-Elf")
elif (dice1 == Halfing):
print(f"You got Halfing")
elif (dice1 == Half_Orc):
print(f"You got Half-Orc")
elif (dice1 == Human):
print(f"You got Human")
elif (dice1 == Tiefling):
print(f"You got Tiefling")
else:
print("You didn't type what I told you to")
print(f"----------------")
#Identity for Dragonborn
nameM1 = ["Arjhan", "Balasar", "Bharash", "Donaar", "Ghesh", "Heskan", "Kriv", "Medrash", "Mehen","Nadarr", "Pandjed", "Patrin","Rhogar", "Shamash", "Shedinn", "Tarhun", "Torinn"]
nameF1 = ["Akra", "Biri", "Daar", "Farideh", "Harann", "Havilar", "Jheri", "Kava", "Korinn", "Mishann", "Nala", "Perra", "Raiann", "Sora", "Surina", "Thava", "Uadjit"]
surname1 = ["Clethtinthiallor", "Daardendrian", "Delmirev", "Drachedandion", "Fenkenkabradon", "Kepeshkmolik", "Kerrhylon", "Kimbatuul", "Linxakasendalor", "Myastan", "Nemmonis","Norixius", "Ophinshtalajiir", "Prexijandilin", "Shestendeliath", "Turnuroth", "Verthisathurgiesh", "Yarjerit"]
gender = input("If you want your character to be male type M and if you want your character bo female type F: ")
Dragonborn_Mname = random.choice(nameM1) + " " + random.choice(surname1)
Dragonborn_Fname = random.choice(nameF1) + " " + random.choice(surname1)
if(dice == Dragonborn or dice1 == Dragonborn and gender == "M"):
print(f"Your name is {Dragonborn_Mname}")
elif(dice == Dragonborn or dice1 == Dragonborn and gender == "F"):
print(f"Your name is {Dragonborn_Fname}")

#Identity for Dwarf
nameM2 = ["Adrik", "Alberich", "Baern", "Barendd", "Brottor", "Bruenor", "Dain", "Darrak", "Delg","Eberk", "Einkil", "Fargrim", "Flint", "Gardain", "Harbek", "Kildrak", "Morgran", "Orsik", "Oskar", "Rangrim", "Rurik", "Taklinn", "Thoradin", "Thorin", "Tordek", "Traubon", "Travok", "Ulfgar", "Veit", "Vondal"]
nameF2 = ["Amber", "Artin", "Audhild", "Bardryn", "Dagnal", "Diesa", "Eldeth", "Falkrunn", "Finellen", "Gunnloda", "Gurdis", "Helja", "Hlin", "Kathra", "Kristryd", "Ilde", "Liftrasa", "Mardred", "Riswynn", "Sannl", "Torbera", "Torgga", "Vistra"]
surname2 = ["Balderk", "Battlehammer", "Brawnanvil", "Dankil", "Fireforge", "Frostbeard","Gorunn", "Holderhek", "Ironfist", "Loderr", "Lutgehr", "Rumnaheim", "Strakeln", "Torunn", "Ungart"]
Dwarf_Mname = random.choice(nameM2) + " " + random.choice(surname2)
Dwarf_Fname = random.choice(nameF2) + " " + random.choice(surname2)
if (dice == Dwarf or dice1 == Dwarf and gender == "M"):
print(f"Your name is {Dwarf_Mname}")
elif (dice == Dwarf or dice1 == Dwarf and gender == "F"):
print(f"Your name is {Dwarf_Fname}")
#Identity for Elf
nameM3 = ["Adran", "Aelar", "Aramil", "Arannis", "Aust", "Beiro", "Berrian", "Carric", "Enialis", "Erdan", "Erevan", "Galinndan", "Hadarai", "Heian", "Himo", "Immeral", "Ivellios", "Laucian", "Mindartis", "Paelias", "Peren", "Quarion", "Riardon", "Rolen", "Soveliss", "Thamior", "Tharivol", "Theren", "Varis"]
nameF3 = ["Adrie", "Althaea", "Anastrianna", "Andraste", "Antinua", "Bethrynna", "Birel", "Caelynn", "Drusilia", "Enna", "Felosial", "Ielenia", "Jelenneth", "Keyleth", "Leshanna", "Lia", "Meriele", "Mialee", "Naivara", "Quelenna", "Quillathe", "Sariel", "Shanairra", "Shava", "Silaqui", "Theirastra", "Thia", "Vadania", "Valanthe", "Xanaphia"]
surname3 = ["Amakiir", "Amastacia", "Galanodel", "Holimion", "Ilphelkiir", "Liadon", "Meliamne" , "Naïlo", "Siannodel", "Xiloscient"]
Elf_Mname = random.choice(nameM3) + " " + random.choice(surname3)
Elf_Fname = random.choice(nameF3) + " " + random.choice(surname3)
if (dice == Elf or dice1 == Elf and gender == "M"):
print(f"Your name is {Elf_Mname}")
elif (dice == Elf or dice1 == Elf and gender == "F"):
print(f"Your name is {Elf_Fname}")
#Identity for Gnome
nameM4 = ["Alston", "Alvyn", "Boddynock", "Brocc", "Burgell", "Dimble", "Eldon", "Erky", "Fonkin", "Frug", "Gerbo", "Gimble", "Glim", "Jebeddo", "Kellen", "Namfoodle", "Orryn", "Roondar", "Seebo", "Sindri", "Warryn", "Wrenn", "Zook"]
nameF4 = ["Bimpnottin", "Breena", "Caramip","Carlin", "Donella", "Duvamil", "Ella", "Ellyjobell", "Ellywick", "Lilli", "Loopmottin", "Lorilla", "Mardnab", "Nissa", "Nyx", "Oda", "Orla", "Roywyn", "Shamil", "Tana", "Waywocket", "Zanna"]
surname4 = ["Beren", "Daergel", "Folkor", "Garrick", "Nackle", "Murnig", "Ningel", "Raulnor", "Scheppen", "Timbers", "Turen"]
Gnome_Mname = random.choice(nameM4) + " " + random.choice(surname4)
Gnome_Fname = random.choice(nameF4) + " " + random.choice(surname4)
if (dice == Gnome or dice1 == Gnome and gender == "M"):
print(f"Your name is {Gnome_Mname}")
elif (dice == Gnome or dice1 == Gnome and gender == "F"):
print(f"Your name is {Gnome_Mname}")
#Identity for Half-Elf
if (dice == Half_Elf or dice1 == Half_Elf and gender == "M"):
print(f"Half-elves use either human or elven naming conventions. You can type your own name for your character, make sure it's meant for a male, first type the name and then the last name.")
Half_Elf_Mname = input("Your name is: ")
elif (dice == Half_Elf or dice1 == Half_Elf and gender == "F"):
print(f"Half-elves use either human or elven naming conventions. You can type your own name for your character, make sure it's meant for a female, first type the name and then the last name.")
Half_Elf_Fname = input("Your name is: ")
#Identity for Halfing
nameM6 = ["Alton", "Ander", "Cade", "Corrin", "Eldon", "Errich", "Finnan", "Garret", "Lindal", "Lyle", "Merric", "Milo", "Osborn", "Perrin", "Reed", "Roscoe", "Wellby"]
nameF6 = ["Andry", "Bree", "Callie", "Cora", "Euphemia", "Jillian", "Kithri", "Lavinia", "Lidda", "Merla", "Nedda", "Paela", "Portia", "Seraphina", "Shaena", "Trym", "Vani", "Verna"]
surname6 = ["Brushgather", "Goodbarrel", "Greenbottle", "High-hill", "Hilltopple", "Leagallow", "Tealeaf", "Thorngage", "Tosscobble", "Underbough"]
Halfing_Mname = random.choice(nameM6) + " " + random.choice(surname6)
Halfing_Fname = random.choice(nameF6) + " " + random.choice(surname6)
if (dice == Halfing or dice1 == Halfing and gender == "M"):
print(f"Your name is {Halfing_Mname}")
elif (dice == Halfing or dice1 == Halfing and gender == "F"):
print(f"Your name is {Halfing_Fname}")
#Identity for Half-Orc
nameM7 = ["Dench", "Feng", "Gell", "Henk", "Holg", "Imsh", "Keth", "Krusk", "Mhurren", "Ront", "Shump", "Thokk"]
nameF7 = ["Baggi", "Emen", "Engong", "Kansif", "Myev", "Neega", "Ovak", "Ownka", "Shautha", "Sutha", "Vola", "Volen", "Yevelda"]

Half_Orc_Mname = random.choice(nameM7) 
Half_Orc_Fname = random.choice(nameF7)
if (dice == Half_Orc or dice1 == Half_Orc and gender == "M"):
print(f"Your name is {Half_Orc_Mname}")
elif (dice == Half_Orc or dice1 == Half_Orc and gender == "F"):
print(f"Your name is {Half_Orc_Mname}")
#Identity for Human
if (dice == Human or dice1 == Human and gender == "M"):
print(f"Being a human yourself I'll let you name your character, make sure it's meant for a male, first type the name and then the last name.")
Human_Mname = input("Your name is: ")
elif (dice == Human or dice1 == Human and gender == "F"):
print(f"Being a human yourself I'll let you name your character, make sure it's meant for a female, first type the name and then the last name.")
Human_Fname = input("Your name is: ")
#Identity for Tiefling
nameM9 = ["Akmenos", "Amnon", "Barakas", "Damakos", "Ekemon", "Iados", "Kairon", "Leucis", "Melech", "Mordai", "Morthos", "Pelaios", "Skamos", "Therai"]
nameF9 = ["Akta", "Anakis", "Bryseis", "Criella", "Damaia", "Ea", "Kallista", "Lerissa", "Makaria", "Nemeia", "Orianna", "Phelaia", "Rieta"]
surname9 = ["Art", "Carrion", "Chant", "Creed", "Despair", "Excellence", "Fear", "Glory", "Hope", "Ideal", "Music", "Nowhere", "Open", "Poetry", "Quest", "Random", "Reverence", "Sorrow", "Temerity", "Torment", "Weary"]
Tiefling_Mname = random.choice(nameM9) + " " + random.choice(surname9)
Tiefling_Fname = random.choice(nameF9) + " " + random.choice(surname9)
if (dice == Tiefling or dice1 == Tiefling and gender == "M"):
print(f"Your name is {Tiefling_Mname}")
elif (dice == Tiefling or dice1 == Tiefling and gender == "F"):
print(f"Your name is {Tiefling_Fname}")

print(f"------------------------------------")

好的,我发现了问题。你有

dice = random.randrange(1, 9)
dice1 = random.randrange(1, 9)

都是赋值。所以当你有以下ifelif语句

if(dice == Dragonborn or dice1 == Dragonborn and gender == "M"):
elif(dice == Dragonborn or dice1 == Dragonborn and gender == "F"):
// and for all other race

即使dice == something为假,它仍然会检查dice1 == something
因此将打印两次名称。
→当dice == something
->当dice1 == something
而不是2个变量,当用户选择滚动时,只需将值重新分配给同一个变量:

dice = random.randrange(1, 9)
....
elif(response == "reroll"):
print(f"You wish to reroll the dice. This is your last roll this round.")
dice = random.randrange(1, 9)

对于ifelif:

if(dice == something and gender == "M"):
elif(dice == something and gender == "F"):

也有太多的代码重复。试着减少它。我做了一些,看看你是否能应用它。这是用于存储数据(mname, fname,姓氏)和使用字典,因为它很适合这里。

race = {
1:'race1',
2:'race2',
3:'race3',
}
data = {
"Dragonbone":{
"M":['mname1','mname2','mname3'],
"F":['fname1','fname2','fname3'],
"surname":['sname1','sname2','sname3']
},
"Half-Orc":{
"M":['mname1','mname2','mname3'],
"F":['fname1','fname2','fname3'],
"surname":[] # leave them empty if they dont get these
},
"Human":{
"M":[],
"F":[],
"surname":[]
},
}

创建这个函数用于生成用户名。

def generateName(race,name,surname):
# checking if name is empty
if not name: 
print(f"Being a {race} yourself I'll let you name your character,first type the name and then the last name.")
yourname = input("Your name is: ")
# checking if surname is empty
elif not surname:
yourname = random.choice(name)
else:
yourname = random.choice(name) + " " + random.choice(surname)
return yourname

用于调用函数,

dice = random.randrange(1, 9)
sex = input("M or F");
# After confirming user for 'continue' or 'reroll'
print(generateName(race[dice],data[race[dice]][sex],data[race[dice]]["surname"]))

这样可以重用并减少大量重复代码。

相关内容

  • 没有找到相关文章

最新更新