Advertisement
am_dot_com

FP20211019

Oct 19th, 2021 (edited)
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.49 KB | None | 0 0
  1. #boolean operators, relational operators
  2. #operands = True , False
  3. #operators = and, or, not
  4. #and, or : binary operators (take 2 operands)
  5. #False is the absorvent element of the and op
  6. #True is the absorvent element of the or op
  7.  
  8. a = True
  9. b = False
  10. logicalAnd = a and b #False, both operands were evaluated
  11. logicalAnd = b and \
  12.              ((True or True) and (False or b)) #False, right-operand was NOT evaluated, because of short-circuit
  13.  
  14. def algorithm(pInfo):
  15.     #sol
  16.     return True
  17. #def
  18.  
  19. i = 3 #literal integer
  20. c = True
  21. d = False #literal boolean
  22. logicalOr = c or d #True, only the left-operand was evaluated
  23. logicalOr = c or algorithm("2021-10-19") #algorith would not be computed
  24.  
  25. """
  26. 2 operands ^ 2 operators = 4
  27. L   R  and
  28. T   T   T
  29. T   F   F
  30. F   T   F
  31. F   F   F
  32.  
  33. L   R  or
  34. T   T   T
  35. T   F   T
  36. F   T   T
  37. F   F   F
  38.  
  39. o   not
  40. T   F
  41. F   T
  42.  
  43. """
  44.  
  45. #relational operators (all binary , all infix)
  46. # > >= < <= == !=
  47. bZeliaAfterArtur = "Zélia" > "Artur"
  48. print (bZeliaAfterArtur) #True
  49. bZeliaAfterArtur = "artur" > "Zélia"
  50. print (bZeliaAfterArtur) #True
  51. #A, B, C, D, E, F .. Z ..... a, b, c, d, e
  52.  
  53. a = 123 ; b = 321 ; c = 123
  54. bComputesFalse = a>c #False
  55. bComputesTrue = a==c #True ; == identical-operator
  56. bComputesTrue = a>=c #True
  57. bComputesTrue = (a>c) or (a==c) #True
  58.  
  59. n1 = 123.123 ; n2 = 123
  60. r = n1 > n2 #True
  61. print ("r= "+str(r)) #type-casting #"r= True"
  62. #procedural abstraction
  63. #print ("r= ", r, sep="*******")
  64. print ("r= ", r, sep="") #"r= True"
  65. print ("r= {}".format(r))
  66.  
  67. #write the 1st 256 non-negative numbers in decimal, octal and hexadecimal
  68. listOfTheFirst256 = range(256) #[0, 255]
  69. for numberThatWillVaryFrom0to255 in listOfTheFirst256:
  70.     """
  71.    %d - decimal
  72.    %o - octal
  73.    %x - hexadecimal
  74.    %s - string
  75.    %f - float
  76.    """
  77.     #s = "iteration nº"+str(n+1)
  78.     #s = "bla bla bla"
  79.     strSomeStringToWriteTheIterationNumber = "iteration " + str(numberThatWillVaryFrom0to255 + 1)
  80.     strSomeStringToWriteTheIterationNumber = "iteration {}".format(numberThatWillVaryFrom0to255 + 1) #only this one applies
  81.     strN = "%d %o %x %s"%(numberThatWillVaryFrom0to255, numberThatWillVaryFrom0to255, numberThatWillVaryFrom0to255, strSomeStringToWriteTheIterationNumber) #right-operand list provides the arguments for the specifiers in the left-operand string
  82.     print (strN)
  83. #for
  84.  
  85. nFloatingPointNumber = 471237/9283
  86. print ("{:3.3f}".format(nFloatingPointNumber))
  87. print ("%3.3f"%(nFloatingPointNumber))
  88.  
  89. True==True
  90. True!=False
  91. 3.3==3
  92. 3.3!=2
  93.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement