Added GPR ue03

This commit is contained in:
Jonas_Jones 2023-11-08 17:20:06 +01:00
parent 3382a22a42
commit 69f6734b81
4 changed files with 53 additions and 1 deletions

30
GPR/ue03/main.py Normal file
View file

@ -0,0 +1,30 @@
'''GPR Übungsblatt 03'''
__author__ = "7987847, Werner"
def dec_to_bin(zahl:int) -> str:
'''Umwandlung einer Dezimalzahl in eine Binärzahl
zahl: Dezimalzahl
'''
if zahl == 0:
return '0'
binzahl = ''
while zahl > 0:
binzahl = str(zahl % 2) + binzahl
zahl //= 2
return binzahl
print("Es wird eine Dezimalzahl in eine Binärzahl umgewandelt.")
print("Geben Sie eine Dezimalzahl ein.")
print(dec_to_bin(int(input("Dezimalzahl: "))))
# Testfälle
# dec_to_bin(0)
# Ausgabe: 0
# dec_to_bin(1)
# Ausgabe: 1
# dec_to_bin(69)
# Ausgabe: 1000101