I am trying to create a character selection CLI using python.
I want to display the user's Current Party of Characters Selected so that they can see who they have already chosen. The user cannot choose the same character twice. A user must have 4 characters to proceed
I have created the following code (I do call it correctly don't worry!):
def ChooseCharacters(): CharList= CurrentParty= print("Select up to 4 explorers!") while len(CharList)!=4: if len(CharList)!=4: if len(CharList)==0: pass else: for CharID in list(set(CharList)): print(CharList) SQL=("SELECT firstname,secondname FROM characters WHERE CharID=%s") mycursor.execute(SQL,(CharID,)) myresult=mycursor.fetchone() Name=(myresult+" "+myresult) CurrentParty= list(set(CurrentParty)) CurrentParty.append(Name) print("Current Party: ",CurrentParty) PrintChoice(CharList) def PrintChoice(CharList): mycursor.execute("SELECT * FROM characters") myresults=mycursor.fetchall() Num=0 for char in myresults: Num = Num + 1 print(str(Num)+("."),char,char) Choice=input("Select Character: ") if Choice in CharList: print("Character already selected!") return CharList.append(Choice) print(CharList)
It appears that the first character chosen is duplicated in the list, the rest of the code works fine.
Current Party: ['Sam Jordan'] Current Party: ['Sam Jordan','Olivia Cope'] Current Party: ['Sam Jordan','Olivia Cope','Dylan Nesbitt']
Current Party: ['Sam Jordan'] Current Party: ['Olive Cope', 'Sam Jordan', 'Sam Jordan'] Current Party: ['Sam Jordan', 'Olive Cope', 'Dylan Nesbitt', 'Sam Jordan']
I can't work out where the second replication of the first input occurs, seeing as the first input is outputs correctly.
If you need to see the database table just ask.