Help with my python code
For one thing, your access to the teacher name and the rank number both lead to the exact same index:
print(staffRanks[staff+1], "was ranked", staffRanks[staff+1], "please enter new rank:")
Remove the +1 in the first staffRanks and you should get the name. Also, you're missing any sort of code to update the rank for current teacher. When it asks for new rank, all you're doing it taking input and printing that input. There's no code to perform an updates to the list.
On a side note... I personally wouldn't use a list like that. I would've used Dictionaries and create a Dictionary for each Teacher with their name and rank, then add those to a list.
https://www.w3schools.com/python/python_dictionaries_add.asp
Take for example:
mylist = [] thisdict = { "name": "John", "rank": 1 } # Add new dictionary to the list mylist.append(thisdict) print (mylist) # Modify the rank for the first item (teacher in this context) in the list mylist[0].update({"rank": 2}) print (mylist) # Accessing individual items based on the key print("Name:", mylist[0].get("name")) print("Rank:", mylist[0].get("rank"))
Results:
[{'name': 'John', 'rank': 1}]
[{'name': 'John', 'rank': 2}]
Name: John
Rank: 2
This way you don't need to do any gymnastics with indexes as they're a common cause of out of bounds errors when you have stuff like index + 1. You can simply iterate through the list using:
for i in mylist: # Code to ask for new rank and update rank here
And another side note, please use code tags instead of screenshots of your code.

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now