Skip to content

Instantly share code, notes, and snippets.

@TheonlyTazz
Last active April 26, 2023 04:21
Show Gist options
  • Save TheonlyTazz/d374efbe514399550724f632d9eb70e4 to your computer and use it in GitHub Desktop.
Save TheonlyTazz/d374efbe514399550724f632d9eb70e4 to your computer and use it in GitHub Desktop.
High Low
def main():
# Definiere Listen und Zähler
numberList = []
low_total = 0
high_total = 0
low_list = []
high_list = []
# Schleife zur Abfrage der Anzahl der Zahlenkette
while True:
amount = input("Geben sie an, wieviel Zahlenketten sie eingeben wollen (Max 10):\n")
if amount.isdigit():
if int(amount) <= 10:
amount = int(amount)
break
print("Bitte geben Sie weniger als 10 Zahlenketten ein.10")
# Schleife zur Eingaben der Zahlenketten
print("\nBitte geben sie ihre Zahlenketten ein:")
for x in range(amount):
while True:
numbers = input(f"{x+1}: ")
if numbers.isdigit():
numberList.append(numbers)
break
# Schleife, der jede Zahlenkette abläuft und den niedrigste und höchste Zahl rausspeichert
for i in numberList:
low_num = 10
high_num = -1
for x in i:
if int(x) < low_num:
low_num = int(x)
if int(x) > high_num:
high_num = int(x)
low_list.append(low_num)
high_list.append(high_num)
# 2 Schleifen um die Zahlenlisten zu addieren (auf möglich mit sum())
"""
low_total = sum(low_list)
high_total = sum(high_list)
"""
for number in low_list:
low_total = low_total + number
for number in high_list:
high_total = high_total + number
# Ausgabe Ergebnis
print("\n\n\n")
print(f"Niedrige Liste: {low_list}")
print(f"Niedrigste Zahlen addiert: {low_total}\n")
print(f"Hohe Liste: {high_list}")
print(f"Hohe Zahlen addiert: {high_total}\n")
print(f"Differenz: {max(high_list)} - {min(low_list)}")
# Start Program, call main()
if __name__ == '__main__':
yes = ["yes", "y", "ja", "j"]
while True:
main()
repeat = input(f"Noch eine Abfrage?\n").lower()
if not repeat in yes:
break
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment