简体   繁体   English

如何为每个人发出邀请?

[英]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. 我是编程新手,我必须挑战列表上的每个人都可以得到邀请,但是我敢肯定必须有一种更简单的方法,而不是更改guest_list[x] 7次。 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. 这是非常基本的Python。 You should do a beginners tutorial befor you ask further questions. 在问更多问题之前,您应该先做一个初学者教程。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 python 在我的 discord 服务器中为每个人创建一个变量? - How can I make a variable for each person in my discord server with python? 如何分组并获取 Dataframe 中每个人的唯一值计数,然后将其写入 Python 中的 Excel 工作表? - How can I groupby and get unique value counts for each person in Dataframe and then write that to an Excel sheet in Python? 如何使不和谐的机器人根据人员在命令中输入的内容来创建角色 - How can I make a discord bot create a role based on what the person types in the command 我将如何做到这一点,以便个人是唯一可以使用 discord 机器人运行命令的人? - How would I make it so that an individual person is the only one who can run a command with a discord bot? 如何检查一个人是否包含在模型中以进行工作/发布 - How can I check whether a person is included in a model to make a Job/Post 如何让我的 Discord 机器人提及频道中的特定人员? - How can i make my Discord bot mention a specific person in the channel? 我怎样才能让我的 discord 机器人在键入时提到特定的人? - How can I make it so my discord bot mentions a specific person when they type? 如何使用不同的代理硒打开每个窗口 - How can I make each window open with different proxy selenium 如何制作一个数组,其中每个元素都是随机图像? - how can I make an array that each element of is a random image? 如何使2个类实例相互引用? - How can I make 2 class instances refer to each other?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM