Python3 – Example of Index, add/remove from index, get input from a user

#our current party in an index.
current_party = ["Wizard","Rogue","Fighter","Cleric"]
#sorts our current party alphabetically
current_party.sort()
print ("Current Adventuring Party\n")
#print our current party
for current_member in current_party:
    print(current_member)

#a member has to leave, so we will take the input from the user, and that party member will be removed from the list.
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:')) 

#Tells the user a member has left
left_member = current_party.pop(index)
print(f'{left_member} has left the party.')

#let us 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}')

#who is in our current party now - Print the current party to our user after changes.
current_party.sort()
for current_member in current_party:
    print(current_member)

#cleanly exits the program
input("press any key to exit program")

Posted

in

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *