Python3 – Example of Index, add/remove from index, get input from a user
#ourcurrentpartyinanindex.current_party= ["Wizard","Rogue","Fighter","Cleric"]#sortsourcurrentpartyalphabeticallycurrent_party.sort()print ("Current Adventuring Party\n")#printourcurrentpartyforcurrent_memberin current_party:print(current_member)#amemberhastoleave,sowewilltaketheinputfromtheuser,andthatpartymemberwillberemovedfromthelist.print(f"\n One of the party members have to leave\n")index=int (input('Enter the index number of the party member who has to leave:')) #Tellstheuseramemberhasleftleft_member=current_party.pop(index)print(f'{left_member} has left the party.')#letus add a member to our party. We take the input from the user,and add that to our current party.new_member=input('\nInput a class to join your party:')print()current_party.append(f'{new_member}')#whoisinourcurrentpartynow-Printthecurrentpartytoouruserafterchanges.current_party.sort()forcurrent_memberin current_party:print(current_member)#cleanlyexitstheprograminput("press any key to exit program")
Leave a Reply