Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Josh Bennett
15,258 PointsPython loop only printing the last tuple, any thoughts?
# Columns: Name, Day/Month, Celebrates, Age
BDAY = (
("James", "9/8", True, 9),
("Shawna", "12/6", True, 22),
("Amaya", "28/2", False, 8),
("Kamal", "29/4", True, 19),
("Sam", "16/7", False, 22),
("Xan", "14/3", False, 34),
)
# Problem 2: Half birthdays
# Loop through all of the people in BIRTHDAYS
# Calculate their half birthday (six months later)
# Print out their name and half birthday
for person in BDAY:
birthdate = person[1].split("/")
birthdate[1] = int(birthdate[1]) + 6
if birthdate[1] > 12:
birthdate[1] - 12
birthdate[1] = str(birthdate[1])
print(person[0], '/'.join(birthdate))
result
Xan 14/9
Why am I only getting the last one?.
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! You're only getting the last one printed because your print statement doesn't run until the for loop is completed. To get each person printed, you will need to include the print inside the for loop. Try indenting your print statement one level.
Hope this helps!
Josh Bennett
15,258 PointsJosh Bennett
15,258 Pointsduuuuuuuhhhh.... Facepalm....