Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
lehrkraefte:blc:informatik:glf20:programmieren:while [2020/10/28 11:43] mirco.triner |
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: |
+ | < | ||
+ | counter += 1 | ||
+ | </ | ||
+ | < | ||
+ | counter = counter + 1 | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <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. | ||
</ | </ | ||
Line 61: | Line 71: | ||
<hidden Lösungvorschläge> | <hidden Lösungvorschläge> | ||
<code python> | <code python> | ||
+ | # | ||
+ | |||
print(" | print(" | ||
- | t = inputInt(" | + | cash = inputInt(" |
- | while t > 0: | + | while cash > 0: |
- | if t//1000 > 0: | + | if cash//1000 > 0: |
- | print(str(t// | + | print(" |
- | | + | |
- | elif t//200 > 0: | + | elif cash//200 > 0: |
- | print(str(t//200) + "x 200.-" | + | print(" |
- | | + | |
- | elif t//100 > 0: | + | elif cash//100 > 0: |
- | print(str(t//100) + "x 100.-" | + | print(" |
- | | + | |
- | elif t//50 > 0: | + | elif cash//50 > 0: |
- | print(str(t//50) + "x 50.-" | + | print(" |
- | | + | |
- | elif t//20 > 0: | + | elif cash//20 > 0: |
- | print(str(t//20) + " | + | print("%d x 20.-" % (cash//20)) |
- | | + | cash = cash%20 |
+ | elif cash//10 > 0: | ||
+ | print("%d x 10.-" | ||
+ | | ||
else: | else: | ||
- | print(str(t//10) + "x 10.-") | + | print(" |
- | | + | |
</ | </ | ||
Line 104: | Line 120: | ||
<code python> | <code python> | ||
+ | #Zahl zwischen 1-100 | ||
to_be_guessed = input(" | to_be_guessed = input(" | ||
guess = 50 | guess = 50 | ||
Line 116: | Line 133: | ||
else: | else: | ||
guess += ((to_be_guessed - guess) // 2) | guess += ((to_be_guessed - guess) // 2) | ||
- | print(" | + | print(" |
counter += 1 | counter += 1 | ||