同时为true:检查名称中是否有名称

时间:2016-12-16 00:18:20

标签: python

amount_of_names = int(input("Input amount of players: "))
names = []

for counter in range(amount_of_names):
    name = str(input("Input players first name: "))
    names.append(name)
#print (names)
selected_name = str(input("Input your name: "))
import random 
names2 = random.choice(names)
while True:
    if name != names2:
        import random 
        names2 = random.choice(names)
        print (name, names2)
        break
    else: names2 = random.choice(names)

Input amount of players: 6
Input players first name: aa
Input players first name: ss
Input players first name: dd
Input players first name: ff
Input players first name: gg
Input players first name: hh
Input your name: ss
hh hh

我希望"而真实"声明一直运行到" name"和"名字"不匹配,如果名称不匹配,则打印不匹配的名称。 Atm我只收到一封信作为输出或语法错误,同时试图使其正常工作,如果它已经在列表中,实际上无法与他们的名字匹配 - 如果有人可以帮助它将非常感激

ArrangementNode

1 个答案:

答案 0 :(得分:0)

amount_of_names = int(input("Input amount of players: "))
names = []

for counter in range(amount_of_names):
  name = str(input("Input players first name: "))
  names.append(name)
#print (names)
selected_name = str(input("Input your name: "))
import random 
names2 = random.choice(names)
while True:
    if name != names2:
        print (name,names2)
        break
    else:
        names2 = random.choice(names)