a
Hey everyone,
I’ve been working on the Intermediate Python 3 course and have gotten stuck on the generator project Event Coordinator and was hoping I could get some help from the group.
The second part of the project requires you to use the send method to input a new guest. The code I have is as follows:
guests = {}
def read_guestlist(file_name):
text_file = open(file_name,‘r’)
while True:
line_data = text_file.readline().strip().split(",")
new_guest = yield line_data
if new_guest != None:
line_data = new_guest
if len(line_data) < 2:
text_file.close()
break
name = line_data[0]
age = int(line_data[1])
guests[name] = age
gen_obj = read_guestlist(‘guest_list.txt’)
for name in range(10):
print(next(gen_obj))
print(gen_obj.send(‘Jane, 35’))
The output of the code is as follows:
[‘Tim’, ‘22’]
[‘Tonya’, ‘45’]
[‘Mary’, ‘12’]
[‘Ann’, ‘32’]
[‘Beth’, ‘20’]
[‘Sam’, ‘5’]
[‘Manny’, ‘76’]
[‘Kenton’, ‘15’]
[‘Kenny’, ‘27’]
[‘Dixie’, ‘46’]
Traceback (most recent call last):
File “script.py”, line 24, in
print(gen_obj.send(‘Jane, 35’))
File “script.py”, line 14, in read_guestlist
age = int(line_data[1])
ValueError: invalid literal for int() with base 10: ‘a’
The send method should produce the outcome of adding [‘Jane’, ’35’] to the list above. I’m unsure of what I’m doing wrong and any help would be greatly appreciated.
The specific exercise is https://www.codecademy.com/courses/learn-intermediate-python-3/projects/int-python-event-coordinator