I´m learning programming in phyton and i had to make a wordsearch generator. Ive made it but i need the result/array to be saved in a csv file. Ive tried a lot but cant seem to find out how, anyone can help me please? Thanks in advance. Sorry for the spanish words in the code as im from Argentina.
This is my code:
import random
def mayor_a_10(numero):
return int(numero) > 10
def pedir_dato(texto):
dato = input(texto)
if(mayor_a_10(dato) == True):
return dato
else:
pedir_dato("ERROR. Ingrese un número mayor a 10: ")
def pedir_datos_tablero():
palabras = []
max_palabras = int(N) / 3
palabra = input("Ingrese una palabra o escriba 'fin' para terminar: ")
palabras.append(str(palabra))
while(palabra != "fin" and len(palabras) < int(max_palabras)):
palabra = input("Ingrese otra palabra o escriba 'fin' para terminar: ")
palabras.append(str(palabra))
return palabras
def generar_tablero(N, palabras):
matriz = []
filas = int(N)
columnas = int(N)
letras =['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'W', 'X', 'Y', 'Z']
for i in range(filas):
matriz.append([0] * columnas)
for f in range(filas):
for c in range(columnas):
letra_random = random.randint(0,24)
matriz[f][c] = letras[letra_random]
for x in matriz:
print(x)
# Programa principal
pedir_dato("Ingrese un número mayor a 10: ")
N = input("Ingrese un número mayor o igual a 15 para la cantidad de columnas y filas: ")
while(int(N) < 5):
N = input("ERROR. Ingrese un número mayor o igual a 15 para las columnas y filas: ")
palabras = pedir_datos_tablero()
tablero = generar_tablero(N, palabras)
What I have tried:
Ive tried a lot of code but i dont fully understand writing to a csv.