Advertisement
rric

Erstelle_deine_Formeln

Oct 17th, 2023
652
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.23 KB | None | 0 0
  1. # Zeigt Berechnungen mit ganzen Zahlen und Kommazahlen
  2. # Copyright 2022 Roland Richter
  3.  
  4. print("=== Arithmetische Operatoren ===")
  5.  
  6. print("Addition: 42 + 3.14 ist", 42 + 3.14)
  7. print("Subtraktion: 42 - 3.14 ist", 42 - 3.14)
  8. print("Multiplikation: 42 * 3.14 ist", 42 * 3.14)
  9.  
  10. print("Division: 17 / 5 ist", 17 / 5)
  11. print("Ganzzahlige Division: 17 // 5 ist", 17 // 5)
  12. print("Rest bei Division (modulo): 17 % 5 ist", 17 % 5)
  13.  
  14. print("=== Zuweisungsoperatoren ===")
  15.  
  16. x = 42
  17. print("mache 'x = 42', und x ist", x)
  18. x += 3.14
  19. print("mache 'x += 3.14', und x ist jetzt", x)
  20.  
  21. y = 42
  22. print("mache 'y = 42', und y ist", y)
  23. y -= 3.14
  24. print("mache 'y -= 3.14', und y ist jetzt", y)
  25.  
  26. z = 42
  27. print("mache 'z = 42', und z ist", z)
  28. z *= 3.14
  29. print("mache 'z *= 3.14', und z ist jetzt", z)
  30.  
  31. print("=== Vergleichsoperatoren ===")
  32.  
  33. if x == y:
  34.     print("x ist gleich y:", x, "==", y)
  35. if x != y:
  36.     print("x ist ungleich y:", x, "!=", y)
  37. if x < y:
  38.     print("x ist kleiner als y:", x, "<", y)
  39. if x > y:
  40.     print("x ist größer als y:", x, ">", y)
  41. if y <= z:
  42.     print("y ist kleiner oder gleich z:", y, "<=", z)
  43. if y >= z:
  44.     print("y ist größer oder gleich z:", y, ">=", z)
  45.  
  46. print("=== Ganze Zahlen (integers) ===")
  47.  
  48. print("Die Antwort ist:", 42)
  49. print("Die Zahl 42 als binäre Zahl:", bin(42))  # starts with prefix 0b
  50. print("Die Zahl 42 als hexadezimale Zahl:", hex(42))  # starts with prefix 0x
  51.  
  52. print(
  53.     "Größte natürliche 8-bit Zahl:",
  54.     bin(0b11111111),
  55.     "=",
  56.     0b11111111,
  57.     "=",
  58.     hex(0b11111111),
  59. )
  60.  
  61. # ----------------------------------------------------------------------
  62. # This program is free software: you can redistribute it and/or modify
  63. # it under the terms of the GNU General Public License as published by
  64. # the Free Software Foundation, either version 3 of the License, or
  65. # (at your option) any later version.
  66. #
  67. # This program is distributed in the hope that it will be useful,
  68. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  69. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  70. # GNU General Public License for more details.
  71. #
  72. # You should have received a copy of the GNU General Public License
  73. # along with this program.  If not, see <https://www.gnu.org/licenses/>.
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement