Advertisement
ProgrammierenLernen

automatische_konvertierung

Sep 16th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. # Automatische Konvertierung
  2.  
  3. zahl = 1250
  4. dividend = 150
  5. divisor = 4
  6.  
  7. print("Zahl:", zahl)  # zahl ist eine Ganzzahl
  8.  
  9. zahl = dividend / divisor  # zahl bekommt einen Fließkommazahl zurück und speichert diese
  10. print("Ganzzahl nach neuer Wertzuweisung:", zahl)
  11.  
  12. zahl = int(zahl)  # Fließkommazahl wird in eine Ganzzahl umgewandelt. Dabei gehen Daten verloren.
  13. print("Wert nach Konvertierung:", zahl)
  14.  
  15.  
  16. # Mit dem doppelten Schrägstrich // wird eine Division durchgeführt
  17. # bei der man als Ergebnis nur eine Ganzzahl zurück bekommt
  18. zahl = 99 // 8
  19. print("Ganzzahlige Division:", zahl)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement