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/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: |
+ | < | ||
+ | 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 68: | Line 78: | ||
while cash > 0: | while cash > 0: | ||
if cash//1000 > 0: | if cash//1000 > 0: | ||
- | print(str(cash// | + | print(" |
cash = cash%1000 | cash = cash%1000 | ||
elif cash//200 > 0: | elif cash//200 > 0: | ||
- | print(str(cash// | + | print(" |
cash = cash%200 | cash = cash%200 | ||
elif cash//100 > 0: | elif cash//100 > 0: | ||
- | print(str(cash// | + | print(" |
cash = cash%100 | cash = cash%100 | ||
elif cash//50 > 0: | elif cash//50 > 0: | ||
- | print(str(cash// | + | print(" |
cash = cash%50 | cash = cash%50 | ||
elif cash//20 > 0: | elif cash//20 > 0: | ||
- | print(str(cash// | + | print(" |
cash = cash%20 | cash = cash%20 | ||
elif cash//10 > 0: | elif cash//10 > 0: | ||
- | print(str(cash// | + | print(" |
cash = cash%10 | cash = cash%10 | ||
else: | else: | ||
print(" | print(" | ||
cash = 0 | cash = 0 | ||
+ | |||
</ | </ | ||
Line 109: | Line 120: | ||
<code python> | <code python> | ||
+ | #Zahl zwischen 1-100 | ||
to_be_guessed = input(" | to_be_guessed = input(" | ||
guess = 50 | guess = 50 |