Booleans values at funtions in Python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Booleans values at funtions in Python

I'm trying to write a code that supposes a online buying; it takes the user information and confirm if it is ok. I wrote a function that confirm if each data is correct with a boolean value, the problem is that the boolean value (defined as False out of the function) only changes inside the function, then it returns to the initial value (False). I tried with "return" after change the value, how I can change it inside the function without it returns to the initial value? (Sorry for my English, I'm still studying) Estoy intentando escribir un código que supone una compra en línea; toma la información del usuario y confirma si es correcto. Escribí una función que confirma si es correcto cada dato con un valor booleano (booleans), el problema es que el valor booleano (definido como Falso fuera de la función) solo cambia dentro de la función, después vuelve al valor inicial (Falso). Intenté con "return" después cambiar el valor, ¿cómo puedo cambiarlo dentro de la función si que regrese al valor inicial?

16th Dec 2020, 2:40 AM
J R
J R - avatar
1 Answer
+ 2
Add the global keyword to the start of the function followed by the variables you want use in the function.. https://code.sololearn.com/cjz9x550MNQB/?ref=app
16th Dec 2020, 2:53 AM
Steve Sajeev
Steve Sajeev - avatar