def greeting(userlist):
for name in userlist:
print("welcome here " + name)
def move(list1, list2):
while list1:
for user in list1:
current_user = list1.pop()
a = "list1"
b = "list2"
print(current_user + " is moved from " + a + " to " + b) ###########
unconfirmed_users = ['xxx', 'yyy', 'zzz']
confirmed_users = []
move(unconfirmed_users, confirmed_users)
greeting(confirmed_users)
原本想在第十行(已用###标记)print出这样的效果
“xxx is moved from unconfirmed_users to confirmed_users".
然而出来的效果是这样的
xxx is moved from list1 to list2
请问怎么达到我想要的效果
def greeting(userlist): for name in userlist: print("welcome here " + name) def move(list1, list2): while list2: for user in list1: current_user = list1.pop() a = list2[0] b = list2[1] print( current_user + " is moved from " + a + " to " + b) ########### unconfirmed_users = ['xxx', 'yyy', 'zzz'] confirmed_users = ['unconfirmed_users', 'confirmed_users'] move(unconfirmed_users, confirmed_users) greeting(confirmed_users)
可能有一点曲解我的意思了,不过我明白怎么解决了,谢谢
你的
a = "list1"
b = "list2"
出来的肯定是xxx is moved from list1 to list2
你要“xxx is moved from unconfirmed_users to confirmed_users".
就把8、9行改成
a = "unconfirmed_users"
b = "confirmed_users
谁说不是呢
但我觉得你想要的不应该是这个
@兰冰点点: 嗯...如果我想多次用这个函数的话这样就不可以了
@skrrr: 所以,请通俗的描述你要干嘛
@兰冰点点: move(unconfirmed users, confirmed users)
move(beautiful users, ugly users)
如何让这个函数既能打出xxx is moved from unconfirmed users to confirmed users
又能打出yyy is moved from beautiful users to ugly users
@skrrr: 你传参数啊,传什么就打印什么
没参数也有个判断逻辑吧,不然你怎么定义什么情况输出什么打印
@兰冰点点: 不好意思大概明白了,谢谢
@兰冰点点: 真不好意思啊
我只能做到用input
def greeting(userlist):
for name in userlist:
print("welcome here " + name)
def move(list1, list2):
a = input("old list\n")
b = input("new list\n")
while list1:
current_user = list1.pop()
print(current_user + " is moved from " + a + " to " + b)
unconfirmed_users = ['xxx', 'yyy', 'zzz']
confirmed_users = []
move(unconfirmed_users, confirmed_users)
greeting(confirmed_users)
但不是我想要的效果,能否省去手动输入这部分,直接在move(unconfirmed_users,confirmed_users)这里就直接将两个列表名储存起来
@兰冰点点:
def greeting(userlist):
for name in userlist:
print("welcome here " + name)
def move(list1, list2):
a = input("old list\n")
b = input("new list\n")
while list1:
current_user = list1.pop()
print(current_user + " is moved from " + a + " to " + b)
unconfirmed_users = ['xxx', 'yyy', 'zzz']
confirmed_users = []
move(unconfirmed_users, confirmed_users)
greeting(confirmed_users)