简体   繁体   中英

How can I make an invitation for each person?

I am new at programming and I have to do a challenge where each person on a list get's an invitation but instead of changing the number in guest_list[x] 7 times, I'm sure there has to be an easier way. Here is what I managed to make. Please feel free to critique me.

plus_one= 'hitler'
guest_list = ['john carter', 'emilia airheart', 'god']
print ("Dear, \n" + guest_list[1].title() + ", you are invited to a warm get together. unfortunately " + busy.title(),"couldn't make it "
      + "but luckily " + plus_one.title() + " managed to appear" )
guest_list.append('hitler')
guest_list.insert(-3, "bob ross")
guest_list.insert(0, 'jerry seinfeld')
guest_list.append('micheal')
print(guest_list)

Is this what you're looking for?

for guest in guest_list:
      print ("Dear, \n" + guest.title() + ", you are invited to a warm get 
              together. unfortunately " + busy.title(),"couldn't make it "
              + "but luckily " + plus_one.title() + " managed to appear")

In order to do something for each entry in guest list you can run a loop:

Simple example:

for guest in guest_list:
  print guest

Now you could define a function that insterts the guest's name into a string and prints it. Then you call that function in the loop.

This is very basic Python. You should do a beginners tutorial befor you ask further questions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM