[Solved] Identify python errors


Works in Python 3.x

import random

players = ["Player 1", "Player 2"]

for p in players:
    x = len(p)
    dice = random.randint(0, x*2)
    print(str(p) + " rolls a " + str(dice) + " out of " + str(x*2))
    if dice > x:
        print(p + " wins!")
    elif dice == x:
        print(p + "gets a tie.")
    else:
        print(p + " loses.")

For Python 2.x

import random

players = ["Player 1", "Player 2"]

for p in players:
    x = len(p)
    dice = random.randint(0, x*2)
    print(str(p) + " rolls a " + str(dice) + " out of " + str(x*2))
    if dice > x:
        print p + " wins!"
    elif dice == x:
        print p + "gets a tie." 
    else:
        print p + " loses."

or add from __future__ import print_function to first example to ensure compability between Python 3 and 2.

1

solved Identify python errors