aufgabe_D1.py
x = input("Gib eine Zahl ein:")
 
print("Das Quadrat der Zahl {0} ist {1}".format(x,x**2))
print("Die Wurzel der Zahl {0} ist {1}".format(x,sqrt(x)))
print("Das 10-fache der Zahl {0} ist {1}".format(x,10*x))
aufgabe_D2.py
from gturtle import *
 
monika = Turtle()
 
x = input("Gib die Seitenlänge des Quadrats ein:")
 
repeat 4:
    monika.forward(x)
    monika.right(90)
aufgabe_D4.py
from gturtle import *
 
monika = Turtle()
 
x = input("Gib die x-Koordinate des Startpunktes ein:")
y = input("Gib die y-Koordinate des Startpunktes ein:")
b = input("Gib die Breite des Rechteckes ein:")
h = input("Gib die Höhe des Rechteckes ein:")
 
monika.setPos(x,y)
 
repeat 2:
    monika.forward(h)
    monika.right(90)
    monika.forward(b)
    monika.right(90)
aufgabe_E1.py
x = input("Tippe eine Zahl ein:")
 
if x > 0:
    print("Die Zahl {0} ist positiv.".format(x))
elif x == 0:
    print("Die Zahl {0} ist genau Null.".format(x))    
else:
    print("Die Zahl {0} ist negativ.".format(x))
aufgabe_E2.py
from gturtle import *
 
vreni = Turtle()
 
s = input("Gib eine Figur an. Zur Auswahl stehen: 'Quadrat' und 'Kreis'")
 
if s == "Quadrat":
    repeat 4:
        vreni.forward(200)
        vreni.left(90)
 
elif s == "Kreis":
    vreni.leftArc(150, 360)
 
else:
    print("Kein zulässiger Input!")
aufgabe_E3.py
import random
 
x = random.randint(0, 10)
y = random.randint(0, 10)
 
antwort = input("Die Summe von {0} und {1} ist:".format(x,y))
 
if antwort == x+y:
    print("Korrekt!")
else:
    print("Leider falsch! Das korrekte Resultat wäre gewesen: {0}".format(x+y))
aufgabe_F1.py
x = input("Gib eine zweistellige Zahl ein:")
 
while x >= 10 and x < 100:
    x = input("Gib eine zweistellige Zahl ein:")
 
print("Game Over! Du hast etwas eingegeben, was keine zweistellige Zahl war.")
aufgabe_F5.py
import random
 
anz_korrekt = 0
anz_fragen  = 0
 
while anz_fragen < 10:
    x = random.randint(0, 10)
    y = random.randint(0, 10)
 
    antwort = input("Die Summe von {0} und {1} ist:".format(x,y))
    anz_fragen = anz_fragen + 1 # oder kurz: anz_fragen += 1
 
    if antwort == x+y:
        print("Korrekt!")
        anz_korrekt += 1
    else:
        print("Leider falsch! Das korrekte Resultat wäre gewesen: {0}".format(x+y))
 
    print("Spielstand: {0} von {1} Fragen richtig".format(anz_korrekt,anz_fragen)) 


aufgabe_F3b.py
import random
import os
 
anz_korrekt = 0
anz_fragen  = 0
anz_fehler  = 0
 
while anz_fehler < 3:
    x = random.randint(0, 10)
    y = random.randint(0, 10)
 
    antwort = input("Die Summe von {0} und {1} ist:".format(x,y))
    anz_fragen = anz_fragen + 1 # oder kurz: anz_fragen += 1
 
    if antwort == x+y:
        print("Korrekt!")
        anz_korrekt += 1
    else:
        print("Leider falsch! Das korrekte Resultat wäre gewesen: {0}".format(x+y))
        anz_fehler = anz_fehler + 1
 
    print("Spielstand: {0} von {1} Fragen richtig".format(anz_korrekt,anz_fragen)) 
 
print("Game Over")


aufgabe_F6.py
# Aufgabe F6
zahl1 = 0
zaehler = 0
while zahl1 < 10 or zahl1 > 99: # Wiederhole solange zahl1 kleiner 10 oder grösse 100 ist. 
    zahl1 = input("Gib eine positive Zweistellige Zahl ein")
 
if zahl1 % 2 == 0: # Wenn zahl1 gerade (Rest der Division durch 2 gibt 0)
    schritt = 2
else:
    schritt = 5
 
while zaehler < zahl1:
    zaehler = zaehler + schritt
    print(zaehler)
  • gf_informatik/programmieren_ii_loesungen.1671283566.txt.gz
  • Zuletzt geändert: 2022-12-17 13:26
  • von gra