elements of a string as an object of true value

Messages in english

Modérateur : xcasadmin

compsystems
Messages : 540
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

elements of a string as an object of true value

Message par compsystems » ven. mai 03, 2019 3:46 pm

Hello

The Python language considers a complete string or the elements of a string as an object of true value,
Does BP consider it convenient for Xcas to work in the same way as Python does in this part? See example # 3.1
that is, each character, since it has its numerical equivalent, then they are values that can be considered true

Code : Tout sélectionner

#cas
def all( iterable ):
    for element_ in iterable:
        if not element_:
            return False
    return True
#end
example # 1

lst1 := [ -5.8, -1, 1, 3.5, 4, 10 ];
print( all( lst1 ) ) [enter] returns
True

example # 2

lst1 := [ -5.8, -1, 1, 3.5, 4, 10, 0 ];
print( all( lst1 ) ) [enter] returns
False

example # 3

tbl1 := table( 65: "A", 97: "a", 215: "×", 247: "÷" );
print( all( tbl1 ) ) [enter]
True

example # 3.1

tbl1 := table("65": "A", "97": "a")
print( all( tbl1 ) ) [enter]
"Error"

Répondre