Versionsvergleich
Aus ProgrammingWiki
Vergleich: 2019-11-17T14:22:53+00:00 → 2019-12-02T20:24:18+00:00
<language>Python</language> | |
Eine mögliche Lösung für das Problem: | |
''Read in integers that represent daily rainfall, and print out the average daily rainfall. If the input value of rainfall is less than zero, prompt the user for a new rainfall. When you read in 99999, print out the average of the positive integers that were input other than 99999.'' | |
<run id="5dd156b4a8d97"> | |
| − | i = int(input('Gib eine Zahl ein:')) |
| + | eingabe = 0 |
| + | zahlen = [] |
| − | print(i) |
| + | while eingabe != 99999: |
| + | eingabe = int(input('Gib eine weitere Zahl ein (99999 für Ende):')) |
| + | if eingabe != 99999 and eingabe >= 0: |
| + | zahlen.append(eingabe); |
| + | |
| + | summe = 0 |
| + | |
| + | for w in zahlen: |
| + | summe = summe + w |
| + | |
| + | anzahl = len(zahlen) |
| + | print("Es wurden insgesamt {} Werte eingegeben {}. Der durchschnittliche Niederschlag ist: {}" |
| + | .format(anzahl,zahlen, (summe / anzahl) if (anzahl > 0) else 0)) |
</run> |