Step 4 in Event Coordinator

I’m in step 4 of the event coordinator project in learning intermediate python3 project.
I’m trying to get a list of people who are 21 or over.
I’ve tried multiple ways to generate the list but I can’t seem to get it to work.

Below is my code:
guests = {}
def read_guestlist(file_name):
text_file = open(file_name,‘r’)
while True:
line_data = text_file.readline().strip().split(“,”)
if len(line_data) < 2:
# If no more lines, close file
text_file.close()
break
name = line_data[0]
age = int(line_data[1])
guests[name] = age
with open(‘guest_list.txt’, ‘r’) as file:
for line in file:
name, age = line.strip().split(‘,’) # Assuming each line is in the format “Name,Age”
yield name, age
guest_generator = read_guestlist(‘guest_list.txt’) # Create the generator object
for _ in range(10): # Limit to the first 10 guests
try:
print(next(guest_generator)) # Print each guest name
except StopIteration:
break
guest_generator_age = read_guestlist(‘guest_list.txt’)

for age in guest_generator_age:
guest_age =
text_file = open(‘guest_list.txt’,‘r’)
line_data = text_file.readline().strip().split(“,”)
name = line_data[0]
age = int(line_data[1])
#guests[name] = age
with open(‘guest_list.txt’, ‘r’) as file:
for line in file:
name, age = line.strip().split(‘,’) # Assuming each line is in the format “Name,Age”
#yield name, age
if int(line_data[1]) >= 21:
guest_age.append(line, line[age])
print(guest_age)

type or paste code here

Hi!, can you post your code again but with the correct format so it is easier to understand?
Try the </> button and then pasting it between the lines
Sin título

I think I figured it now. Thanks.

1 Like