Oct-13-2025, 08:35 AM (This post was last modified: Oct-13-2025, 10:20 AM by deanhystad.)
Hi,
My very first post so hope I get it right.
I have been learning Pythin for a week now and it seems to be going well.
I am on an exercise where I am generating invites to a list opf guests and as you can see I have been deleting, appending and inserting and all is fine.
My question is (an not sure it is possible) I just want to type one line of code that sends the same message to all the people in my list. In the very last line I have tried changing the people[0] (the very last line which prints to Ozzy only) to [0:-1] or [:] to basically print the same message to all of them individually. I feel like I am missing something but as you can see I do not want to have a line of code for each guest if the list is growing.
Thanks in advance
Nev
My very first post so hope I get it right.
I have been learning Pythin for a week now and it seems to be going well.
I am on an exercise where I am generating invites to a list opf guests and as you can see I have been deleting, appending and inserting and all is fine.
My question is (an not sure it is possible) I just want to type one line of code that sends the same message to all the people in my list. In the very last line I have tried changing the people[0] (the very last line which prints to Ozzy only) to [0:-1] or [:] to basically print the same message to all of them individually. I feel like I am missing something but as you can see I do not want to have a line of code for each guest if the list is growing.
Thanks in advance
Nev
people = ['rick mayall', 'chris cornell', 'kurt cobain', 'meatloaf'] invite_0 = f"\n Dear {people[0].title()}, please come to my party on Saturday!" invite_1 = f"\n Dear {people[1].title()}, please come to my party on Saturday!" invite_2 = f"\n Dear {people[2].title()}, please come to my party on Saturday!" invite_3 = f"\n Dear {people[3].title()}, please come to my party on Saturday!" print(invite_0) print(invite_1) print(invite_2) print(invite_3) dropout = f"\n {people[3].title()} can not attend my party." print(dropout) del people[3] people.append ('albert einstein') invite_3 = f"\n Dear {people[3].title()}, please come to my party on Saturday!" print(invite_0) print(invite_1) print(invite_2) print(invite_3) new_message = f"\n {people[0].title()} I have found a new bigger table so will be inviting more people." print(new_message) new_message = f"\n {people[1].title()} I have found a new bigger table so will be inviting more people." print(new_message) new_message = f"\n {people[2].title()} I have found a new bigger table so will be inviting more people." print(new_message) new_message = f"\n {people[3].title()} I have found a new bigger table so will be inviting more people." print(new_message) people.insert (0,'ozzy ozbourne') people.insert (2,'elvis presley') people.append ('freddie mercury') print(people) latest_message = f"\n {people[0].title()} I have found a better much bigger table so will be inviting more people." print(latest_message)#how do I write one line that writes an individual letter to all the people tried adding [0:-1] after people deanhystad write Oct-13-2025, 10:20 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
