[英]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.