Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #boolean operators, relational operators
- #operands = True , False
- #operators = and, or, not
- #and, or : binary operators (take 2 operands)
- #False is the absorvent element of the and op
- #True is the absorvent element of the or op
- a = True
- b = False
- logicalAnd = a and b #False, both operands were evaluated
- logicalAnd = b and \
- ((True or True) and (False or b)) #False, right-operand was NOT evaluated, because of short-circuit
- def algorithm(pInfo):
- #sol
- return True
- #def
- i = 3 #literal integer
- c = True
- d = False #literal boolean
- logicalOr = c or d #True, only the left-operand was evaluated
- logicalOr = c or algorithm("2021-10-19") #algorith would not be computed
- """
- 2 operands ^ 2 operators = 4
- L R and
- T T T
- T F F
- F T F
- F F F
- L R or
- T T T
- T F T
- F T T
- F F F
- o not
- T F
- F T
- """
- #relational operators (all binary , all infix)
- # > >= < <= == !=
- bZeliaAfterArtur = "Zélia" > "Artur"
- print (bZeliaAfterArtur) #True
- bZeliaAfterArtur = "artur" > "Zélia"
- print (bZeliaAfterArtur) #True
- #A, B, C, D, E, F .. Z ..... a, b, c, d, e
- a = 123 ; b = 321 ; c = 123
- bComputesFalse = a>c #False
- bComputesTrue = a==c #True ; == identical-operator
- bComputesTrue = a>=c #True
- bComputesTrue = (a>c) or (a==c) #True
- n1 = 123.123 ; n2 = 123
- r = n1 > n2 #True
- print ("r= "+str(r)) #type-casting #"r= True"
- #procedural abstraction
- #print ("r= ", r, sep="*******")
- print ("r= ", r, sep="") #"r= True"
- print ("r= {}".format(r))
- #write the 1st 256 non-negative numbers in decimal, octal and hexadecimal
- listOfTheFirst256 = range(256) #[0, 255]
- for numberThatWillVaryFrom0to255 in listOfTheFirst256:
- """
- %d - decimal
- %o - octal
- %x - hexadecimal
- %s - string
- %f - float
- """
- #s = "iteration nº"+str(n+1)
- #s = "bla bla bla"
- strSomeStringToWriteTheIterationNumber = "iteration " + str(numberThatWillVaryFrom0to255 + 1)
- strSomeStringToWriteTheIterationNumber = "iteration {}".format(numberThatWillVaryFrom0to255 + 1) #only this one applies
- strN = "%d %o %x %s"%(numberThatWillVaryFrom0to255, numberThatWillVaryFrom0to255, numberThatWillVaryFrom0to255, strSomeStringToWriteTheIterationNumber) #right-operand list provides the arguments for the specifiers in the left-operand string
- print (strN)
- #for
- nFloatingPointNumber = 471237/9283
- print ("{:3.3f}".format(nFloatingPointNumber))
- print ("%3.3f"%(nFloatingPointNumber))
- True==True
- True!=False
- 3.3==3
- 3.3!=2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement