Init
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
|
||||
# This is a comment
|
||||
print('Hello World!')
|
||||
@@ -0,0 +1,3 @@
|
||||
for _ in range(100):
|
||||
# print('Ich darf Sophia nicht umdrehen.')
|
||||
print('Ich darf Sophia nicht umdrehen.', end=' ')
|
||||
@@ -0,0 +1,18 @@
|
||||
# Werte und Typen
|
||||
|
||||
x = 17
|
||||
print(type(x))
|
||||
|
||||
y = '17'
|
||||
print(type(y))
|
||||
|
||||
z = 17.0
|
||||
print(type(z))
|
||||
|
||||
|
||||
# Eingabe mit Ignorierung der Rückgabe
|
||||
input('Gib Deinen Namen ein: ')
|
||||
|
||||
# Eingabe mit Speicherung der Rückgabe
|
||||
user_name = input('Gib Deinen Namen ein: ')
|
||||
print('Hallo', user_name)
|
||||
@@ -0,0 +1,32 @@
|
||||
# Typen und ihre Konvertierung
|
||||
def typfehler():
|
||||
p = '10'
|
||||
for _ in range(p):
|
||||
print('no way!')
|
||||
|
||||
print(int("10"))
|
||||
#print(int("10.6"))
|
||||
#print(int("A"))
|
||||
print(int(10.0))
|
||||
print(int(10.3))
|
||||
print(int(10.7))
|
||||
|
||||
print(str(10.7))
|
||||
|
||||
print(float(10))
|
||||
print(float("10"))
|
||||
print(float("10.7"))
|
||||
#print(float("A"))
|
||||
|
||||
# Range erwartet Ganzzahlen
|
||||
p = '10'
|
||||
for _ in range(int(p)):
|
||||
print('way!')
|
||||
|
||||
# Ganzzahlige Division // vs Gleitkomma-Division /
|
||||
print(3 // 2)
|
||||
print(3 / 2)
|
||||
|
||||
# Boolescher Typ
|
||||
t = True
|
||||
print(type(t))
|
||||
@@ -0,0 +1,29 @@
|
||||
# Thema: Ausdrücke
|
||||
|
||||
# Ausführungsreihenfolge
|
||||
print(3 * 4 - 8 // 2)
|
||||
print(3 * (4 - 8) // 2)
|
||||
|
||||
# Operatoren bei unterschiedlichen Typen
|
||||
print(4.0 + 2)
|
||||
print (4 * 2.0)
|
||||
print(4 / 2)
|
||||
|
||||
# Formatierte Ausgabe
|
||||
print(f'Das Ergebnis ist {3+4}')
|
||||
|
||||
s = 'Haus'
|
||||
z = 7
|
||||
print(f'{s:10} ist ein Gebäude')
|
||||
print(f'{z:010} ist eine Zahl')
|
||||
|
||||
euro = 20 / 3
|
||||
print(f'Das kostet {euro:.2f} €.')
|
||||
|
||||
|
||||
# Mehrere Ausdrücke in einem f-String
|
||||
eingabe = 5
|
||||
print(f'Das Quadrat von {eingabe} ist {eingabe*eingabe:.2f}')
|
||||
|
||||
|
||||
print(f'{3+4} {3*4} {3-4} {3/4} {3//4} {3%4} {3**4}')
|
||||
@@ -0,0 +1,17 @@
|
||||
# Berechnen des Durchschnitts einer Liste von Zahlen
|
||||
|
||||
sum = 0.0
|
||||
count = 0
|
||||
|
||||
while True:
|
||||
input_text = input("Geben Sie eine Zahl ein (0 bricht ab): ")
|
||||
number = float(input_text)
|
||||
if number == 0:
|
||||
break
|
||||
sum = sum + number
|
||||
count = count + 1
|
||||
|
||||
if count == 0:
|
||||
print("Keine Zahlen eingegeben")
|
||||
else:
|
||||
print(f"Der Durchschnitt ist {sum / count:.3f}")
|
||||
@@ -0,0 +1,11 @@
|
||||
# Funktion mit einer Rückgabe
|
||||
def mal_drei(x):
|
||||
return x * 3
|
||||
|
||||
print(mal_drei(5))
|
||||
|
||||
|
||||
# Jede Funktion in Python gibt einen Wert zurück.
|
||||
r = print("Hello World!")
|
||||
print(r)
|
||||
print(type(r))
|
||||
@@ -0,0 +1,6 @@
|
||||
# Berechnung einer Kreisfläche
|
||||
|
||||
PI = 3.14159
|
||||
radius = float(input("Bitte den Radius eingeben: "))
|
||||
area = PI * radius * radius
|
||||
print("Der Flächeninhalt beträgt", area)
|
||||
Reference in New Issue
Block a user