samedi 11 septembre 2021

TypeError: unsupported operand type(s) for +: 'int' and 'str' while trying to combine randint and

I've seen several other versions of this question from 2014 and earlier, yet they all seem to be very far off what I need.

Code:

 while Play == True:
computernum = str(random.randint(1,19))
playernum = str(random.randint(1,10))
print(str("Your first number is " + playernum + "."))
playinput1 = input("Do you want to roll another number? <Y or N> ")
if playinput1 == "Y":
    playernum0 = int(random.randint(1,10))
    playernum2 = int(playernum0 + playernum)
    break

Error response:

    *Traceback (most recent call last):
  File "program.py", line 41, in <module>
    playernum2 = int(playernum0 + playernum)
TypeError: unsupported operand type(s) for +: 'int' and 'str'*



Aucun commentaire:

Enregistrer un commentaire