无法转换' tuple'隐含地反对str

时间:2014-05-06 22:34:12

标签: python

a=int(input("please input number of players  "))
while (a < 2):
a=int(input("please input at least two players  "))
if (a==2):
p1=input("please enter name for player 1  ")
p2=input("please enter name for player 2  ")
x=float(input("please enter initiative for "+(p1)))
y=float(input("please enter initiative for "+(p2)))
x=x,p1
y=y,p2
if (x > y):
    lowest=y
    highest=x
elif(y > x):
    lowest=x
    highest=y
print(lowest)
steps=int(input("Please enter number of steps for "+(lowest)+" action" ))

我已经尝试了我能想到的一切,但它需要做到这一点,但我无法弄清楚如何让它发挥作用

1 个答案:

答案 0 :(得分:2)

这正是消息所说的:在最后一行,在子表达式中

"Please enter number of steps for "+(lowest)+" action" 

您正在尝试将字符串与元组(lowest - 连接起来 - 因为它是xy,并且由于赋值{{1},它们都是元组}和x=x,p1),这需要从元组到字符串的隐式转换。

要解决此问题,您必须将元组显式转换为字符串(y=y,p2)(尽管我怀疑您实际上只想显示元组中的一个元素)。

相关问题