不支持的操作数类型(int)+(var)错误

时间:2019-01-11 10:02:39

标签: python

P1Roundx=int (0)
P2Roundx=int(0)
P1Scorex=int(0)
P2Scorex=int(0)
P1Total=int(0)
P2Total=int(0)
number=int(0)
P1R1=int(0)
P2R1=int(0)
P1R2=int(0)
P2R2=int(0)

import time

Username=input("what is player 1’s username") 
Username=str(Username)
if Username == ("1"):
    print ("hello",Username,)
elif Username == ("2"):
    print ("welcome",Username,)
else:
    print("LEAVE!")
    exit()       
          # This module determines if player 1 is authenticated or if they are not. If they are not they are forced to exit the programme

Username2=input("what is player 2's username")
Username2=str(Username2)
if Username2 == ("2"):
    print ("hello,",Username2,)
elif Username2 == ("1"):
    print ("welcome",Username2,)
else:
    print("LEAVE!")
    exit()       

# This module determines if player 2 is authenticated or not and exits the programme if they are not


import random   
P1R1= random.randint(1,6)
P1R1=("Your first roll is",P1R1)
P1R2=random.randint(1,6)
P1R2=("Your second roll is",P1R2)
print("Your total is",P1R1+P1R2)
P1total=P1R1+P1R2

if P1Total % 2 == 0:
    P1Total=(P1Total)+P1R1
else:
    P1Total=(P1Total)-5+P1R1+P1R2

print("Player 1's total score is",P1Total)

import random           
P2R1= random.randint(1,6)
P2R1=("Your first roll is",P2R1)
P2R2=random.randint(1,6)
P2R2=("Your second roll is",P2R2)
print("Your total is",P2R1+P2R2)
P2total=P2R1+P2R2
if P2Total % 2 == 0:
    P2Total=(P2Total)+ P2R1+P2R2
else:
    P2Total=(P2Total)-5+P2R1

print("Player 2's total score is",P2Total)
time.sleep(6)

是一个错误,但我不知道var + int在哪里。我需要帮助。 顺便说一句,我对这个斯纳凯汀不太好

2 个答案:

答案 0 :(得分:2)

代码执行此操作

script

def changeSet = script.currentBuild.changeSets[0]; 是1到6之间的数字;假设它是4。但是代码确实是

P1R1= random.randint(1,6)

您似乎打算将其打印出来作为消息。但是实际上是将P1R1的值更改为元组P1R1=("Your first roll is",P1R1) 。然后,您的代码将继续运行,好像P1R1仍然具有值("Your first roll is",4),因为它在上面进行了加法运算。

如果您查看此行的输出:

P1R1

您会看到它是

4

很明显你在期待

print("Your total is",P1R1+P1R2)

应该很容易理解为什么代码在此之后出错。

答案 1 :(得分:0)

hi删除以下为P1R1和P2R2指定元组的行

P1R1=("Your first roll is",P1R1)
P2R2=("Your second roll is",P2R2)