am_dot_com

IA20211018-2

Oct 18th, 2021 (edited)
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #math operators
  2. #+ - * / // % ** **(1/n)
  3. a = 3 ; b = 2
  4. theSum = a + b #5
  5. print(theSum,end="\n") #writes the expression to the stdout stream / standard output stream
  6. theDif = a-b #1
  7. print(theDif)
  8. print(theSum, theDif, sep=" | ")
  9. print(theSum, sep=" | ")
  10. print(theDif)
  11.  
  12. a=30;b=2
  13. floatingPointDivision = realDivision = a/b #15.0
  14. print(realDivision)
  15. integerDivision = a//b #15
  16. print(integerDivision)
  17.  
  18. a=3;b=2
  19. remainderOfTheIntegerDivision=a%b #1
  20. print(remainderOfTheIntegerDivision)
  21.  
  22. aSquared = a**2
  23. print(aSquared) #9
  24. squareRoot = aSquared**(1/2)
  25. type(squareRoot) #float
  26. print(squareRoot)
  27.  
  28. print("squareRoot= "+str(squareRoot))
  29. print("squareRoot=", squareRoot)
  30. print("squareRoot= {}".format(squareRoot))
  31. print("squareRoot= {:3.1f}".format(squareRoot))
  32. print("squareRoot= %3.1f"%(squareRoot))
  33.  
  34. #d decimal | s string | x hexadecimal | o octal
  35. d=123; s="Hello!"
  36. print("decimal=%d o=%o h=%x ; frase=%s" \
  37. %(d, d, d, s))
  38.  
  39. for n in range(256): #col [0..255]
  40. strDecimalAndHexa = "n= %3d h= %2x"%(n,n)
  41. print(strDecimalAndHexa)
  42. #for
Add Comment
Please, Sign In to add comment