Generation

generate functionThu, 08 Jun 2023

Dissenyeu la funci´o readPosition tal que, donada la mida del tauler, retorni una llista de coordenades, amb les posicions x i y llegides del teclat. Cal verificar que les dues posicions siguin v`alides (´es a dir, que hagin superat la comprovaci´o de la funci´o checkBounds. Aix´ı, un exemple d’´us de la funci´o podria ser el seg¨uent: >>> readPosition(5) Insert position to play ( x:y, starting from 0 ): 22:0 Wrong position. Insert position to play ( x:y, starting from 0 ): 0:0 [0:0]

def readPosition(n): while True: x, y = input("Insert position to play ( x:y, starting from 0 ): ").split(':') if checkBounds(x, y, n): break # if the position in correct we break return [x,y]

Want to kickstart your project?Use the new AI Studio to create your code