0
How to have a message where “person was not initially in the list” in Python
Hi guys I was wondering how would you have a message appear If The Input removeName was not In the list. E.g removeName = Liz but Liz was not In the original list so It could say “Liz was not In the list?” def removeFromBasketball(): if removeStudent == ("YES"): removeName = input("Enter the name.\n").upper() teams["basketball"].remove(removeName) print(removeName, "has been removed from the database.") print("The updated basketball team member list is:", teams["basketball"]) Thank you :)
2 Respostas
+ 1
You could nest another if statement inside your first one, here's an example in pseudocode:
def removeFromBasketball():
if removeStudent == ("YES"):
removeName = input("Enter the name.\n").upper()
if removeName in list:
//do your code above
else if removeName not in list:
//print your not in list message
0
I've made a copy of your code and annotated it here, please let me know if something doesn't make sense: https://code.sololearn.com/c0JlIGdlmw30/#py
It was good the way you convert the input to upper to make sure the text matches the dictionary, well done! You need to be careful of your variable names and indentation though. It would also be a good idea to add an 'else' to your if/else in removeFromBasketball and inout loops to catch anything other than what you have explicitly coded,