如何为每个人制作邀请?

2024-10-06 09:51:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我是一个编程新手,我必须做一个挑战,让列表中的每个人都得到一个邀请,但不是把数字改7次,我相信一定有更简单的方法。这是我设法做到的。请随意批评我。你知道吗

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)

Tags: to方法列表title编程plus数字one
3条回答

这就是你要找的吗?你知道吗

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")

为了对来宾列表中的每个条目执行操作,您可以运行一个循环:

简单示例:

for guest in guest_list:
  print guest

现在可以定义一个函数,将来宾的名字插入到字符串中并打印出来。然后在循环中调用该函数。你知道吗

这是非常基本的Python。在你进一步提问之前,你应该先做一个初学者教程。你知道吗

这就是你要找的吗?你知道吗

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")

相关问题 更多 >