lehrkraefte:blc:informatik:glf20:programmieren:while

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
lehrkraefte:blc:informatik:glf20:programmieren:while [2020/10/30 13:14]
mirco.triner [Lösungsvorschläge]
lehrkraefte:blc:informatik:glf20:programmieren:while [2020/10/30 13:21] (current)
mirco.triner
Line 22: Line 22:
  
 <WRAP info> <WRAP info>
-Bei einer While-Schleife kann es leicht passieren, dass die Schleife endlos weiterläuft. Im Gegensatz zu einer For-Schleife muss die Variable bei einer While-Schleife manuell verändert werden.+Die folgenden Codeblöcke führen zum gleichen Ergebnis: 
 +<code> 
 +counter += 1 
 +</code> 
 +<code> 
 +counter = counter + 1 
 +</code> 
 +</WRAP> 
 + 
 +<WRAP alert> 
 +Bei einer While-Schleife kann es leicht passieren, dass die Schleife endlos weiterläuft. Im Gegensatz zu einer For-Schleife muss die Variable bei einer While-Schleife manuell verändert werden. Speichern Sie deshalb Ihr Programm, bevor Sie es ausführen.
 </WRAP> </WRAP>
  
Line 68: Line 78:
 while cash > 0: while cash > 0:
     if cash//1000 > 0:     if cash//1000 > 0:
-        print(str(cash//1000) + "x 1000.-")+        print("%d x 1000.-" % (cash//1000))
         cash = cash%1000         cash = cash%1000
     elif cash//200 > 0:     elif cash//200 > 0:
-        print(str(cash//200) + "x 200.-")+        print("%d x 200.-" % (cash//200))
         cash = cash%200         cash = cash%200
     elif cash//100 > 0:     elif cash//100 > 0:
-        print(str(cash//100) + "x 100.-")+        print("%d x 100.-" % (cash//100))
         cash = cash%100         cash = cash%100
     elif cash//50 > 0:     elif cash//50 > 0:
-        print(str(cash//50) + "x 50.-")+        print("%d x 50.-" % (cash//50))
         cash = cash%50         cash = cash%50
     elif cash//20 > 0:     elif cash//20 > 0:
-        print(str(cash//20) + "x 20.-")+        print("%d x 20.-" % (cash//20))
         cash = cash%20         cash = cash%20
     elif cash//10 > 0:     elif cash//10 > 0:
-        print(str(cash//10) + "x 10.-")+        print("%d x 10.-" % (cash//10))
         cash = cash%10         cash = cash%10
     else:     else:
         print("und noch ein wenig Münz")         print("und noch ein wenig Münz")
         cash = 0         cash = 0
 +
 </code> </code>
  
Line 109: Line 120:
  
 <code python> <code python>
 +#Zahl zwischen 1-100
 to_be_guessed = input("Neue Zahl: ") to_be_guessed = input("Neue Zahl: ")
 guess = 50 guess = 50
  • lehrkraefte/blc/informatik/glf20/programmieren/while.1604060060.txt.gz
  • Last modified: 2020/10/30 13:14
  • by mirco.triner