1.4 - Attendance tracker

You have two parallel arrays: one stores pupil names and the other stores their attendance counts. First, display everyone’s current attendance. Then show the heading “Today’s attendance check” and ask “Was X present?” for each pupil, updating their attendance if the answer is “yes”. Finally, display the updated attendance for all pupils.

names = ["Jane", "John", "Jess", "Ava"]
attendance = [5, 3, 4, 3]
Previous attendance:
Jane - 5
John - 3
Jess - 4
Ava - 3

Today's attendance check:
Was Jane present? yes
Was John present? no
Was Jess present? yes
Was Ava present? yes

Updated attendance:
Jane - 6
John - 3
Jess - 5
Ava - 4

 

set names to ["Jane", "John", "Jess", "Ava"]
set attendance to [5, 3, 4, 3]

print "Previous attendance:"
loop for length of names array
    print name at current position and attendance at current position
print blank line

print "Today's attendance check:"
loop for length of names array
    ask "Was " + name at current position + " present?" and store answer
    if answer is "yes"
        add 1 to attendance at current position
print blank line

print "Updated attendance:"
loop for length of names array
    print name at current position and attendance at current position

 

names = ["Jane", "John", "Jess", "Ava"]
attendance = [5, 3, 4, 3]

# Show previous attendance
print("Previous attendance:")
for i in range(len(names)):
    print(names[i] + " - " + str(attendance[i]))
print()

# Attendance check
print("Today's attendance check:")
for i in range(len(names)):
    answer = input("Was " + names[i] + " present? ")
    if answer == "yes":
        attendance[i] += 1

# Show updated attendance
print()
print("Updated attendance:")
for i in range(len(names)):
    print(names[i] + " - " + str(attendance[i]))

# Parallel arrays: one stores pupil names, the other stores their attendance counts
names = ["Jane", "John", "Jess", "Ava"]
attendance = [5, 3, 4, 3]

# Show previous attendance
print("Previous attendance:")
for i in range(len(names)):
    print(names[i] + " - " + str(attendance[i]))

print()  # Blank line for spacing

# Attendance check
print("Today's attendance check:")
for i in range(len(names)):
    # Ask if the current pupil was present
    answer = input("Was " + names[i] + " present? ")
    # If they were present, increase their attendance by 1
    if answer == "yes":
        attendance[i] += 1

# Show updated attendance after today’s check
print()
print("Updated attendance:")
for i in range(len(names)):
    print(names[i] + " - " + str(attendance[i]))

Extension

Change the program so it only accepts “yes” or “no”.
If the user types anything else, ask the question again until they give a valid answer.

Today's attendance check:
Was Jane present? maybe
Please type 'yes' or 'no'.
Was Jane present? YES
Please type 'yes' or 'no'.
Was Jane present? yes
Was John present? no
Was Jess present? potato
Please type 'yes' or 'no'.
Was Jess present? no
Was Ava present? yes